我想知道是否有人可以解释以下之间的区别:
$reactive(this).attach($scope);
this.helpers({
parties: () => { //arrow function definition
return Parties.find({});
}
});
和
let reactiveContext = $reactive(this).attach($scope);
reactiveContext.helpers({
parties: function() { //function definition
return Parties.find({});
}
});
我已经阅读了有关箭头函数及其如何处理 this
(即 why the `this` is not work in arrow function of ES6? )
但在这种情况下,我们如何在 helpers
中定义 party
并不重要?因为 this
在此示例中不存在。我错了吗?
我了解箭头函数
在以下情况下很有用:
this.subscribe('parties', () => {
return [
{
limit: parseInt(this.perPage),
skip: parseInt((this.getReactively('page') - 1) * this.perPage),
sort: this.getReactively('sort')
}
]
});
其中,即 this
(在 this.perPage
中)绑定(bind)到封闭上下文。
最佳答案
当函数内部未使用 this
时,没有区别。
它们的行为相同。
关于javascript - this.helpers 中的箭头函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34773968/