Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 CoffeeScript 的新手。我今天遇到了这个。
example -> a ->
和
example -> b =>
细箭和粗箭有什么区别?
有人可以解释一下区别以及何时应该使用它们。
粗箭头=>定义了一个绑定到当前值的函数this。
=>
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; };