和有什么不同?我是CoffeeScript的新手。今天我遇到了这个。CoffeeScript,=>和 - >
example ->
a ->
和
example ->
b =>
这是什么细箭头VS脂肪箭头之间有什么不同?
是否有人可以解释一下它们的区别以及它们应该使用的时间。
和有什么不同?我是CoffeeScript的新手。今天我遇到了这个。CoffeeScript,=>和 - >
example ->
a ->
和
example ->
b =>
这是什么细箭头VS脂肪箭头之间有什么不同?
是否有人可以解释一下它们的区别以及它们应该使用的时间。
胖箭头=>
定义了一个绑定到当前值this
的函数。
这对回调尤其方便。
通知所产生的差异
咖啡脚本:
foo =() -> this.x + this.x;
bar =() => this.x + this.x;
的JavaScript
var bar, foo,
_this = this;
foo = function() {
return this.x + this.x;
};
bar = function() {
return _this.x + _this.x;
};
这个问题似乎是题外话,因为它是关于不阅读文档。 – rlemon
@ rlemon我不觉得这是脱离主题,我正在阅读文档,并不理解。 – Tyler
@Tyler ==> right here:http://coffeescript.org/#fat-arrow – Neal