cno*_*gr8 15 javascript ecmascript-6 arrow-functions
我正在阅读ScrollListView的源代码,在几个地方我看到了使用() => {}.
如在线25,
this.cellReorderThreshold = () => {
var ratio = (this.CELLHEIGHT*this.cellsWithinViewportCount)/4;
return ratio < this.CELLHEIGHT ? 0 : ratio;
};
Run Code Online (Sandbox Code Playgroud)
第31行,
this.container.addEventListener('scroll', () => this.onScroll(), false);
Run Code Online (Sandbox Code Playgroud)
第88行.
resizeTimer = setTimeout(() => {
this.containerHeight = this.container.offsetHeight;
}, 250);
Run Code Online (Sandbox Code Playgroud)
这是一个简写function,如果它有任何不同,怎么样?
thr*_*qon 23
这是ES6的新箭头语法.它的不同之处在于this:根据调用上下文(传统语义)function得到一个,但是箭头函数保留了定义的上下文.thisthis
见http://tc39wiki.calculist.org/es6/arrow-functions/
ECMAScript 6
arrow function引入了,箭头(=>)部分的arrow function语法。
箭头函数的工作方式与传统的 JavaScript 函数不同。我发现这篇文章解释了与传统函数的区别:http : //www.nczonline.net/blog/2013/09/10/understanding-ecmascript-6-arrow-functions/
| 归档时间: |
|
| 查看次数: |
4149 次 |
| 最近记录: |