【发布时间】:2015-04-20 17:10:19
【问题描述】:
如example 所示,分配给a 和定义b 会导致不同的函数类型。
export module A {
export class Test {
constructor(){}
a =(x) => { return Math.sin(x); }
b (x) : any { return Math.sin(x); }
}
}
这会导致以下 js
var Test = (function () {
function Test() {
this.a = function (x) {
return Math.sin(x);
};
}
Test.prototype.b = function (x) {
return Math.sin(x);
};
return Test;
})();
但是,我对规范 4.9.2 箭头函数表达式
有点困惑Thus, the following examples are all equivalent:
(x) => { return Math.sin(x); }
(x) => Math.sin(x)
x => { return Math.sin(x); }
x => Math.sin(x)
那么,有没有办法使用箭头运算符并在原型上定义一个函数。 比如,
c(x) => Math.sin(x)
【问题讨论】:
标签: javascript typescript arrow-functions