Promise thenable All In One
Promise thenable All In One
Promise thenable 是指一个函数或一个对象的里面定义了一个 then 方法

Promises/A+

https://promisesaplus.com/#terminology
https://github.com/then/promise
https://github.com/then/thenable/blob/master/index.js
// Wrapped
function Wrapped(thenable) {
this.val = thenable;
}
Wrapped.prototype.unwrap = function () {
return this.val;
};
// wrap
function wrap(thenable) {
return new Wrapped(thenable);
}
// unwrap
function unwrap(wrapped) {
return wrapped instanceof Wrapped ? wrapped.unwrap() : wrapped;
}
exports.wrap = wrap;
exports.unwrap = unwrap;
ECMA 262
https://tc39.es/ecma262/#sec-newpromiseresolvethenablejob
MDN
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
refs
https://javascript.info/promise-chaining
class Thenable {
constructor(num) {
this.num = num;
}
then(resolve, reject) {
alert(resolve); // function() { native code }
// resolve with this.num*2 after the 1 second
setTimeout(() => resolve(this.num * 2), 1000); // (**)
}
}
new Promise(resolve => resolve(1))
.then(result => {
return new Thenable(result); // (*)
})
.then(alert); // shows 2 after 1000ms
https://masteringjs.io/tutorials/fundamentals/thenable
https://exploringjs.com/es6/ch_promises.html#sec_chaining-promises
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
Promise thenable All In One的更多相关文章
- 大白话讲解Promise(二)理解Promise规范
上一篇我们讲解了ES6中Promise的用法,但是知道了用法还远远不够,作为一名专业的前端工程师,还必须通晓原理.所以,为了补全我们关于Promise的知识树,有必要理解Promise/A+规范,理解 ...
- JavaScript 初识Promise 对象
什么是Promise? 其实, Promise就是一个类,而且这个类已经成为ES6的标准,是 ECMAScript 6 规范的重要特性之一.这个类目前在chrome32.Opera19.Firefox ...
- Promise库
标准 https://promisesaplus.com/ An open standard for sound, interoperable JavaScript promises—by imple ...
- JavaScript之Promise学习笔记
一直想知道Promise到底是怎么实现的,网上一搜几十篇文章,看的一脸蒙蔽.最后算是找到几个讲的真心很详细明了的.看了一份源码看了很久很久……最后找大佬问了几处看不懂的地方,大佬只看了十几分钟就看懂了 ...
- Promise使用手册
导读 Promise问世已久, 其科普类文章亦不计其数. 遂本篇初衷不为科普, 只为能够温故而知新. 比如说, catch能捕获所有的错误吗? 为什么有些时候会抛出"Uncaught (in ...
- 只会用就out了,手写一个符合规范的Promise
Promise是什么 所谓Promise,简单说就是一个容器,里面保存着某个未来才会结束的事件(通常是一个异步操作)的结果.从语法上说,Promise 是一个对象,从它可以获取异步操作的消息.Prom ...
- Promise简单实现--摘抄
Promise 看了些promise的介绍,还是感觉不够深入,这个在解决异步问题上是一个很好的解决方案,所以详细看一下,顺便按照自己的思路实现一个简单的Promise. Promise/A+规范: 首 ...
- Promise A+ 规范【中文版】
0. 前言 本文为Promise A+规范的中文译文,Promise A+规范英文版原文链接:Promise A+. 正文如下: 一个开放.健全且通用的 JavaScript Promise 标准.由 ...
- 掘金转载-手写一个Promise
目录 一 什么是Promise ? 二 Promises/A+ 规范 2.1 术语 2.2 基本要求 2.2.1. Promise的状态 2.2.2. Then 方法 2.3 简易版实践 2.4 进一 ...
随机推荐
- Java安全之ysoserial-JRMP模块分析(一)
Java安全之ysoserial-JRMP模块分析(一) 首发安全客:Java安全之ysoserial-JRMP模块分析(一) 0x00 前言 在分析到Weblogic后面的一些绕过方式的时候,分析到 ...
- uwsgi 启动django
1, django 官方文档可配置项如下: 2,启动django 的配置: 1,和settings.py 同级目录下新建wsgi.py (该配置和manager.py 的配置基本是一样的) impo ...
- 【Android初级】如何动态添加菜单项(附源码+避坑)
我们平时在开发过程中,为了灵活多变,除了使用静态的菜单,还有动态添加菜单的需求.今天要分享的功能如下: 在界面的右上角有个更多选项,点开后,有两个子菜单:关于和退出 点击"关于", ...
- selenium八大元素定位方法
1.ID定位 可以根据元素的id来定位属性,id是当前整个HTML页面中唯一的,所以可以通过id属性来唯一定位一个元素,是首选的元素定位方式.(动态ID不做考虑) # 导入webdriver和By f ...
- Azure DevOps Pipelines执行RobotFramework自动化代码
一.Azure DevOps介绍 1.什么是 Azure DevOps? Azure DevOps其实是VSTS(Visual Studio Team Service)更名后的名字.而VSTS是TFS ...
- There are only two hard things in Computer Science: cache invalidation and naming things.
TwoHardThings https://martinfowler.com/bliki/TwoHardThings.html https://github.com/cch123/golang-not ...
- Linux 安装mysql总结
第一步:mysql安装包准备 mysql官网下载地址:https://downloads.mysql.com/ 第二步:将mysql安装包上传到服务器 第三步:解压 tar -zxvf mysql-5 ...
- (十六)配置多数据源,整合MybatisPlus增强插件
配置多数据源,整合MybatisPlus增强插件 多数据简介 MybatisPlus简介 1.案例实现 1.1 项目结构 1.2 多数据源配置 1.3 参数扫描类 1.4 配置Druid连接池 1.5 ...
- ajax 用fom提交
$.ajax({ type : "POST", url : "${ctx}/credit/LoanauditCtrl/qwe.do?hetong="+heton ...
- JavaHomeWorkList
3.17 关键词:剪刀石头布:随机数 1 import java.util.Scanner; 2 public class JSB { 3 public static void main(String ...