【发布时间】:2019-07-19 06:23:54
【问题描述】:
要访问对象的方法,我们使用点运算符,例如nameOfObject.nameOfMethod()。这就是我对点运算符的理解。
对点运算符的这种理解并不能帮助我理解 JavaScript 中的 Promise 语法。例如看下面的代码:
var askMom = function () {
willIGetNewPhone // calling the promise
.then(function (fulfilled1) {
// yay, you got a new phone
console.log(fulfilled);
})
.then(function (fulfilled2) {
// yay, you got a new phone
console.log(fulfilled2);
})
.catch(function (error) {
// ops, mom don't buy it
console.log(error.message);
});
}
在我看来,代码好像在说 - nameOfObject.thenMehtod().thenMethod().catchMethod();
我怎么理解这个?是不是意味着在JavaSript中使用nameOfObject.method1().method2().method3;调用对象的方法是正常的
【问题讨论】:
-
.不仅限于函数。您可以使用.运算符访问任何属性。试试这个a = {'a': 'a'}; a.a
标签: javascript promise