1.对象状态不受外界影响,Promise对象代表一个异步操作
有三种状态
pending(进行中)
fulfilled(已成功)
reject(已失败)
then方法是定义在原型对象Promise.prototype上的
等待态(pending);promise包装任务正在执行中;
完成态(fulfilled),promise包装的异步任务执行了resolve函数
拒绝态(rejected);promise执行了reject函数
Promise提供了then方法,该方法可传入2函数,第一个函数是resolve回调函数,第二个函数是reject回调函数
catch与then()方法第二个参数一样
promise.then(function(data){
console.info(data);
},function(err)
{
console.info(err)
});
promise.then(function(data){
console.info(data);
}),catch(function(err)
{
console.info(err)
});