1.promise/A+规范规定 promise 是一个拥有 then 方法的对象或函数,其行为符合本规范;一个 Promise 的当前状态必须为以下三种状态中的一种:等待态(Pending)、执行态(Fulfilled)和拒绝态(Rejected)。 const PENDING = 'pendin ...
转载 2021-08-20 15:47:00
191阅读
2评论
const pending = 'pending' const fulfilled = 'fulfilled' const rejected = 'rejected' class MyPromise { #state = pending #result = undefined #handler =
原创 2024-05-27 10:54:05
40阅读
const resolvePromise = (promise2,x,resolve,reject) => { if(promise2 === x){ return reject(new TypeError('Chaining cycle detected for promise #<Promise>')) } let called; if(typeof x ===
edn
原创 2022-02-10 11:11:42
10000+阅读
Promise 本身是同步 真正的异步是你自己在promise内部写的代码 开始实现promise 大概逻辑 1. 实例化构造函数,构造函数内部调用传入的function,把resolve和reject传给function 2. 紧接着调用then方法,把then方法上的一些函数储存起来:(成功函数 ...
转载 2021-10-22 21:44:00
56阅读
2评论
// _Promise.js // 先定义三个常量表示状态 const PENDING = 'pending'; const FULFILLED = 'fulfilled'; const REJECTED = 'rejected'; function isFunction(fn) { return ...
转载 2021-09-10 10:50:00
68阅读
2评论
Promise 本身是同步 真正的异步是你自己在promise内部写的代码 开始实现promise 大概逻辑 1. 实例化构造函数,构造函数内部调用传入的function,把resolve和reject传给function 2. 紧接着调用then方法,把then方法上的一些函数储存起来:(成功函数 ...
转载 2021-10-22 21:44:00
133阅读
2评论
const PENDING = "pending"; const FULF
原创 2023-05-13 22:20:28
59阅读
手写Promise
原创 2021-07-10 10:45:21
186阅读
<script> const PENDING="pending"; const FULFILLED = "fulfiled"; const REJECTED = "rejected"; function MyPromise(fn){ let _this=this; _this.state=PENDING;
原创 2022-02-11 14:57:53
57阅读
最近在项目中promise的应用场景还是很多的,于是乎决定研究下promise源码,当然不是最底层的源码!下边用ES6类来实现下promise对象:1、先来看下es6给提供的Promise刚开始(图一)的状态一定是pedding(等待),值为undefined;1秒之后,异步队列中的函数 resolve( '成功' ) 开始执行,所以我们会看到状态是resoved(执行完毕,已
原创 2020-02-02 21:33:43
41阅读
先说一下大致的思路,可能并不是按照这么个顺序,我也是模仿Promise的基本使用,就想起来啥总结啥,我觉得应是把
Promise的用法 :let p = new Promise(function(resolve, reject){     console.log(111)     setTimeout(function(){         resolve(2)     }, 1000) }) p.then(function(res){     console.log('suc',res) },functio
转载 2021-02-09 09:45:01
148阅读
2评论
const resolvePromise = (promise2,x,resolve,reject) => { if(promise2 === x){ return reject(new TypeError('Chaining cycle detected for promise #<Promise>')) } let called; if(typeof x === 'function' || (typeof x === 'object' && typeof x
原创 2021-07-13 09:20:27
100阅读
。 现代浏览器支持已经支持了promise,下面我用Cpromise类来重新写一个promise,探索一下promise实现的原理: 直接上代码: /* Cpromise:构造函数 excutor:内部同步执行函数 (resolve,reject) => {} */ function Cpromis ...
转载 2021-08-15 12:22:00
101阅读
2评论
Promise 有三种状态:Pending 初始态; Fulfilled 成功态; Rejected 失败态 Promise是一种异步解决方案, 只能有以下两种方式,不可逆,不可以取消, 状态变化两个形式: 第一种:Pending -> Fulfilled 第一种:Pending -> Reject ...
转载 2021-08-22 20:36:00
79阅读
2评论
1、Promise 的声明 首先呢,promise肯定是一个类,我们就用class来声明。• 由于 new Promise((resolve, reject)=>{}) ,所以传入一个参数(函数),秘籍里叫他executor,传入就执行。•executor里面有两个参数,一个叫resolve(成功) ...
转载 2021-09-26 14:58:00
82阅读
2评论
Promises/A+: https://promisesaplus.com/[译]Promise/A+ 规范: https://zhuanlan.zhihu.com/p/143204897
原创 2022-06-19 01:12:52
10000+阅读
//promise三种状态(运行中,执行成功,执行失败)const PENDING='pending'const RESOLVE='fulfilled'const REJECTED='rejected'function MyPromise(executor){ this.data=undefined this.Fullcallback=[]//存放成功的回调 this.Failedcallback=[]//存放失败的回调 this.status=PENDIN.
IT
原创 2021-09-03 13:27:28
70阅读
Promise基本 Promise执行器resolve, reject, then(同步)resolve(异步,基于发布订阅)then 链式调用 p.then().then();基本链式调用:在 then 里面返回 promise需要考虑 then return 的是 promise 还是普通值x 如果是 promise 则,需要考虑调用 resolve 还是 rejectx 如果是普通值
原创 2022-04-27 17:06:57
10000+阅读
Promise.all() 接收一个 Promise 数组,返回一个新的 Promise,当所有的 Promise 都成功时,该 Promise 会成功,返回一
  • 1
  • 2
  • 3
  • 4
  • 5