如本例所示,分配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)