【发布时间】:2021-01-15 18:05:02
【问题描述】:
这是一个基本问题。我正在通过一个名为 promise-it-wont-hurt 的异步编程 js/node 研讨会。我有以下练习:
Create a promise. Have it fulfilled with a value of 'FULFILLED!' in
executor after a delay of 300ms, using setTimeout.
Then, print the contents of the promise after it has been fulfilled by passing
console.log to then.
我的 test.js 文件包含:
var promise = new Promise(function (fulfill, reject) {
setTimeout(() => 'FULFILLED!',300);
});
promise.then((r)=> console.log(r));
当我在命令行运行“node test.js”时,我没有得到任何输出。我做错了什么?
【问题讨论】:
标签: javascript node.js