Promise管理与链式调用详解.pdfVIP

  • 0
  • 0
  • 约6.96千字
  • 约 8页
  • 2026-08-04 发布于北京
  • 举报

承诺.原型.then()

then方法返回的是一个新的Promise(注意,,原来那个Promise实例)。因此可以链式写法,即then方

法后面再调用另一个方法。

1getJSON(/users.json).then(function(json){2

returnjson.name;3}).then(function(name){

console.log(n4am5});

上面的的代代码使用then方法,依次指定了两个回调函数。。第一个回调函数完成以后,会将返

回结果作为为参参数数,,传入第二个回调函数

一直.then的情况

1le1=getJSON)p1.then(res={console.log(res/0})

2p1.then(res=console.log(res);//0})p1.then={console.log(res);//

30})p1.then(res={console.log(res);//0}).then(function(){

console.log(res);//undefined})console.log(p1.then()instanceof

5Promise);//true.then()方法也会返回调用方法的Promise

文档评论(0)

1亿VIP精品文档

相关文档