ES6 Promise:
https://segmentfault.com/a/1190000011652907
https://es6.ruanyifeng.com/#docs/promise
press F12
1. Promise()需要传入一个函数,这个函数有2个参数,分别是2个函数名
new Promise(function(){}) //"pending
new Promise(function(fn1, fn2){}) //"pending

2. 如果第一个函数执行了,则Promise的状态变为 fulfilled
i1=new Promise(function(fn1, fn2){ fn1("fn1 run")}); i1
//[[PromiseState]]: "fulfilled"
//[[PromiseResult]]: "fn1 run"

3. 如果第二个函数执行了,则Promise的状态变为 rejected,同时报错
i2=new Promise(function(fn1, fn2){ fn2("fn2 run")}); i2
//[[PromiseState]]: "rejected"
//[[PromiseResult]]: "fn2 run"
Uncaught (in promise) fn2 run


4. 如果接着执行 .then(fnSucceed(arg1){}, fnFailed(arg1){}),

(1) 之前状态是 fulfilled 执行前面的函数
i1.then(function(arg1){console.log("1", arg1)}, function(arg1){console.log("2", arg1)}) //1 fn1 run

(2) 之前状态是 rejected 执行后面的函数
i2.then(function(arg1){console.log("1", arg1)}, function(arg1){console.log("2", arg1)}) //2 fn2 run

(3) 对于错误的,还可以链式执行一个.catch(),Promise的状态再次变为 fulfilled

i2_=i2.catch(function(arg){	console.log("Error:", arg) }); //Error: fn2 run
i2_ 
//[[PromiseState]]: "fulfilled"
//[[PromiseResult]]: undefined