我正在学习有关 Javascript 中 Promise 的教程。我在很多地方看到了 then() 方法的用法。
当我编写下面的代码时,我在控制台的 __proto__
部分看到了“then()”函数。
const myPromise = new Promise(function(resolve, reject) {});
console.log(myPromise);
但是当我编写下面的代码时,我无法观察到相同的“then()”函数,
class Car {
constructor(color, type, doors) {
this.color = color;
this.type = type;
this.doors = doors
}
}
const myCar = new Car('blue', 'sedan', '4');
console.log(myCar);
所以,我在想,我们可以在 Javascript 中创建自己的 then()
函数并执行它吗?
最佳答案
看看this博客文章。当你完成后,你应该对 Promise 的含义有一个非常清晰的了解。
关于javascript - 我可以在 Javascript 中创建自己的 "then()"函数并执行它吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55701494/