箭头函数 '() => {}' 在Javascript中是什么意思?

20

我在阅读ScrollListView源代码时,发现多次使用了() => {},例如在第25行。

this.cellReorderThreshold = () => {
    var ratio = (this.CELLHEIGHT*this.cellsWithinViewportCount)/4;
    return ratio < this.CELLHEIGHT ? 0 : ratio;
};

第31行,

this.container.addEventListener('scroll', () => this.onScroll(), false);

第88行。

resizeTimer = setTimeout(() => {
    this.containerHeight = this.container.offsetHeight;
}, 250);

这是一个代替 function 的速记法,如果有任何不同之处,是什么?


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions - Sirko
2个回答

29

2
请注意浏览器兼容性 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Functions/Arrow_functions - user3455363
1
Mozilla的兼容性表似乎没有经常更新。请查看我们的表格以获取最新支持情况-https://kangax.github.io/compat-table/es6/#arrow_functions - kangax

6

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接