2020-09-29 22:09:05 +02:00

1.6 KiB

id, title, challengeType, forumTopicId, localeTitle
id title challengeType forumTopicId localeTitle
5cdafbb0291309899753167f Create a JavaScript Promise 1 301197 创建一个 JavaScript Promise

Description

Promise 是异步编程的一种解决方案 - 它在未来的某时会生成一个值。任务完成,分执行成功和执行失败两种情况。Promise 是构造器函数,需要通过 new 关键字来创建。构造器参数是一个函数,该函数有两个参数 - resolvereject。通过它们来判断 promise 的执行结果。用法如下:
const myPromise = new Promise((resolve, reject) => {

});

Instructions

创建一个名为 makeServerRequest 的 promise。给构造器函数传入 resolvereject 两个参数。

Tests

tests:
  - text: 应该给名为 <code>makeServerRequest</code> 的变量指定一个 promise。
    testString: assert(makeServerRequest instanceof Promise);
  - text: promise 应该接收一个函数做为参数,该函数应该包含 <code>resolve</code> 和 <code>reject</code> 两个参数。
    testString: assert(code.match(/Promise\(\s*(function\s*\(\s*resolve\s*,\s*reject\s*\)\s*{|\(\s*resolve\s*,\s*reject\s*\)\s*=>\s*{)[^}]*}/g));

Challenge Seed


Solution

const makeServerRequest = new Promise((resolve, reject) => {

});