npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

front_promise

v1.0.3

Published

一款零搭建的Promise

Readme

1.什么是 promise?

  它是 es6 提供的异步新的解决方案,没有 promise 的时候 JS 中的异步操作函数往往通过回
  调函数来实现异步任务的结果处理;从语法上来说它是一个构造函数,可以实例化对象,
  封装异步操作可以获取成功与失败的节点,其优点是支持链式调用,解决回调地狱,回
  调函数方式更为灵活,减少嵌套

2.什么是异步?

  同步按你的代码顺序执行,异步不按照代码顺序执行,异步的执行效率更高

3.异步使用场景?

  网络请求,如 ajax 图片加载
  定时任务,如 setTime
  文件读取

4.什么是回调地狱?

  回调函数嵌套调用,外部回调函数异步执行结果是嵌套的回调执行条件

5.回调地狱的缺点?

  不利于阅读,不利于异常处理

6.promise 状态

  实列对象中的一个属性【PromiseState/(sdt)】状态只有两种 pending=>resolved pending=>rejected
  *pending 未决定
  *resolved / fullfilled 成功
  \*rejected 失败

7.promise 对象的值

实列对象中的另一个属性【PromsieResult】
保存着对象【成功、失败】的结果

8.promise api

promise (executor(rzkt))
executor 函数:执行器 (resolve,resject)=>{}
resolve 函数:内部定义成功是我们调用的函数 (value)=>{}
resject 函数:内部定义失败是我们调用的函数(err)=>{}
说明:executor 会在 promise 内部立即同步调用,异步在执行器里面执行
promise.prototype.then 方法:(onresolved,onresjectd)=>{}
onresolved 函数:成功回调函数
onresjectd 函数:失败回调函数
说明:then 方法会返回一个新的 Promise 实例,所以可以进行链式调用,
并且 then 方法接收的是成功还是失败可以通过上一个 Promise 的状态判断。
promise.prototype.catch()方法(onresjectd)=>{}
onresjectd 函数:失败回调函数
promise.resolve 方法:它是函数对象的并不属于实列对象
//如果传入的参数为非 promise 类型的对象,则返回的结果为成功的 promise 对象
//如果传入的参数为 promise 类型的对象,则参数的结果决定了 resolve 的结果
Promise.reject 方法: (reason) => {}
reason: 失败的原因
说明: 返回一个失败的 promise 对象
Promise.all 方法: (promises) => {}
promises: 包含 n 个 promise 的数组
说明: 返回一个新的 promise, 只有所有的 promise 都成功才成功, 只要有一个失败了就直接失败
Promise.race 方法: (promises) => {}
promises: 包含 n 个 promise 的数组
说明: 返回一个新的 promise, 第一个完成的 promise 的结果状态就是最终的结果状态