【发布时间】:2017-02-20 13:53:27
【问题描述】:
我正在使用 node.js v6.7.0 并在声明一个引用 'this' 的对象时,如果它在箭头函数内部,它会返回 undefined 但是当它在常规匿名函数内部时,它会返回对象本身(是我想要的)
例如
let obj = {
key: 'val',
getScopeWithArrow: () => {return this;}, //returns undefined
getScopeWithAnonymous: function() {return this;} //returns the object properly
}
【问题讨论】:
-
@T.J.Crowder 箭头函数有一些特别之处,我以这种方式投影它。
标签: javascript node.js javascript-objects arrow-functions