2
我是Typescript的新手,尝试将它引入到我的某些内容中,但我在使用某些范围和箭头函数时遇到了困难。Typescript - 带参数的箭头函数
在JavaScript中,我的代码看起来像这样...
var model = params.model;
model.Prototypes.bind('change', function(e){
// some code to execute when the event occurs
model.set([some values]); // this performs an operation to the actual top level model
});
好了,所以这有两个问题。当我在Typescript中这样做时,我这样做...
class ClassName {
model: any;
subscribe() {
this.model.Prototypes.bind("change", function(e){
// FIRST PROBLEM
this.model ....
});
}
}
好的,所以这个工作起来,直到标记的部分。 this.model
不再是我认为它的参考,因为它是在功能的背景下,而不是'班'。所以我做了一些挖掘并了解到我应该使用arrow function
,因为这样可以保留上下文。
问题是,我无法想象如何做一个箭头功能,仍然通过我需要的参数,如change
价值的绑定事件,或function(e)
部分。我只看到完全没有参数的例子。