Promise
var p = new Promise(function(resolve, reject){
setTimeout(function(){
console.log('执行完成');
resolve('随便什么数据');
}, 2000);
});
p.then(function(value){console.log(value)})
随便什么数据
var a=0;
var p = new Promise(function(resolve, reject){
for(var i=0;i<4;i++){
a+=1;
}
resolve(a);
});
p.then(function (value) {
console.log(value);
})
// 4