//将异步包装成一个promise new Promise(function(resolve,reject){ setTimeout(function(){ resolve(1); },2000) console.log('promise init'); }).then(res => { console.log(res); }); console.log('window'); var promise = new Promise(function (resolve){ console.log("inner promise"); // 1 resolve(42); }); promise.then(function(value){ console.log(value); // 3 }); console.log("outer promise"); // 2