JavaScript Promise迷你书(中文版).................................................................................... 14 Promise.resolve ................................................................................................ ................................................................................... 56 Promise.resolve和Thenable ....................................................................................... .................................................................................. 107 Promise.resolve ................................................................................................0 码力 | 112 页 | 1010.02 KB | 1 年前3
阮一峰 《ECMAScript 6入门》 第三版Promise(function(resolve, reject) { // ... some code if (/* 异步操作成功 */){ resolve(value); } else { reject(error); } }); Promise 构造函数接受一个函数作为参数,该函数的两个参数分别 是 resolve 和 reject 。它们是两个函数,由 。它们是两个函数,由 JavaScript 引擎提供,不用自己部 署。 resolve 函数的作用是,将 Promise 对象的状态从“未完成”变为“成功”(即从 pending 变为 resolved),在异步操作成功时调用,并将异步操作的结果,作为参 数传递出去; reject 函数的作用是,将 Promise 对象的状态从“未完成”变为“失 败”(即从 pending 变为 rej 对象传出的值作为参数。 下面是一个 Promise 对象的简单例子。 function timeout(ms) { return new Promise((resolve, reject) => { setTimeout(resolve, ms, 'done'); }); } timeout(100).then((value) => { console.log(value);0 码力 | 679 页 | 2.66 MB | 1 年前3
Node.js Manual & DocumentationContents Synopsis 概要 Global Objects 全局对象 o global o process o require() o require.resolve() o require.paths o __filename o __dirname o module Timers 定时器 o setTimeout(callback [options]) Path 路径模块 o path.normalize(p) o path.join([path1], [path2], [...]) o path.resolve([from ...], to) o path.dirname(p) o path.basename(p, [ext]) o path.extname(p) o path.exists(p 模块 o dns.lookup(domain, family=null, callback) o dns.resolve(domain, rrtype='A', callback) o dns.resolve4(domain, callback) o dns.resolve6(domain, callback) o dns.resolveMx(domain, callback)0 码力 | 153 页 | 1.21 MB | 1 年前3
在 JavaScript 中的并行语言特性-周爱民置值之后该怎么办? 如何处理理重写? State Result Reactions1 Reactions2 Resolve 实例例 置值器器 Reject Resolving Functions Promise Instance { Promise.resolve('Hello World') .then(console.log); aPromise.then(func) then(func2, func3) Promise.resolve(x) var p = new PromiseInstnace(); var [resolve, reject] = ... of p; resolve(x); // p[[result]] = x; return p; ≈ p2 = Promise.resolve(p) ≈ var p2 = new PromiseInstnace(); PromiseInstnace(); var [resolve, reject] = ... of p2; p.then(resolve, reject); // resolve(p); return p2; State Result Reactions1 Resolve Reject Reactions2 p = Promise.resolve(x) p2 = p.then(f) JS 类 对象 构造器0 码力 | 41 页 | 8.61 MB | 1 年前3
NodeJS 中文文档 V0.2.3require('dns')来访问这个模块。 下面是一个先解析'www.google.com',然后将解析出来的 IP 地址再做反向解析。 var dns = require('dns'); dns.resolve4('www.google.com', function (err, addresses) { if (err) throw err; console.log('addresses: ' + IPv4或 IPv6的地址的字符串。family 是 一个表示地址版本的整形数字4或6(并不一定是解析域名时传递的数字)。 dns.resolve(domain, dns.resolve(domain, dns.resolve(domain, dns.resolve(domain, rrtype='A', rrtype='A', rrtype='A', rrtype='A', callback) callback) 的 message 属性是一个用英语表述的错误解释。 dns.resolve4(domain, dns.resolve4(domain, dns.resolve4(domain, dns.resolve4(domain, callback) callback) callback) callback) 与 dns.resolve()类似,但是仅对 IPV4地址进行查询(A records)。addresses0 码力 | 62 页 | 542.14 KB | 1 年前3
廖雪峰JavaScript教程alert('支持Promise!'); 我们先看一个最简单的Promise例子:生成一个0-2之间的随机数,如果小于1,则等待一段时间后返 回成功,否则返回失败: 1. function test(resolve, reject) { 2. var timeOut = Math.random() * 2; 3. log('set timeout to: ' + timeOut + ' setTimeout(function () { 5. if (timeOut < 1) { 6. log('call resolve()...'); 7. resolve('200 OK'); 8. } 9. else { 10. log('call reject(). test() 函数有两个参数,这两个参数都是函数,如果执行成功,我们将调用 resolve('200 OK') ,如果执行失败,我们将调用 reject('timeout in ' + timeOut + ' seconds.') 。可以看 出, test() 函数只关心自身的逻辑,并不关心具体的 resolve 和 reject 将如何处理结果。 6.6 Promise - 1560 码力 | 264 页 | 2.81 MB | 10 月前3
《玩转webpack》 第二章 基础篇: webpack 基础用法require('path'); module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') }, + module: { + rules: [ + { + test: /\.js$/, + require('path'); module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') }, + module: { + rules: [ + { + test: /\.css$/, + require('path'); module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') }, + module: { + rules: [ + { + test: /\.less$/, +0 码力 | 41 页 | 2.52 MB | 1 年前3
ThinkJS 1.2 中文文档socket.onopen = function(event) { deferred.resolve(socket); socket.onmessage = function(event) { }else{ deferred.resolve(body); } }) return deferred 该⻚页⾯面列举的函数都是全局函数,不⽤用 require 可以直接使⽤用。 ThinkJS 中的 Promise 使⽤用了 es6-promise 库,是个全局对象, 含有如下的⽅方法: all(array) resolve(promise | thenable | obj) reject(obj) race(array) superCls function ⽗父类 prop function | object0 码力 | 104 页 | 1.29 MB | 1 年前3
Kotlin 1.9.10 官方文档 中文版
directory was build/distributions . However, this is a common directory for Gradle archives. To resolve this issue, we've changed the default distribution target directory in Kotlin 1.9.0 to: build your projects include builds with a specified rootProject.name , composite builds may fail to resolve the Kotlin metadata. For the workaround and details, see this Youtrack issue. We encourage you warning for when this scenario is detected. The warning includes a possible migration path to resolve this issue. If you use such constructs in your code, we recommend updating them to the below: import0 码力 | 3753 页 | 29.69 MB | 1 年前3
Kotlin 官方文档中文版 v1.9directory was build/distributions . However, this is a common directory for Gradle archives. To resolve this issue, we've changed the default distribution target directory in Kotlin 1.9.0 to: build/ your projects include builds with a specified rootProject.name , composite builds may fail to resolve the Kotlin metadata. For the workaround and details, see this Youtrack issue. We encourage you to compiler warning for when this scenario is detected. The warning includes a possible migration path to resolve this issue. If you use such constructs in your code, we recommend updating them to the below: import0 码力 | 2049 页 | 45.06 MB | 1 年前3
共 304 条
- 1
- 2
- 3
- 4
- 5
- 6
- 31













