ES6 箭头函数

//错误的
const contains = (() => Array.prototype.includes ? (arr, value) => arr.includes(value) : (arr, value) => arr.some(el => el === value))();
contains(['foo','bar'],'baz');
false

//正确的
const contains = (() => Array.prototype.includes ? (arr, value) = > arr.includes(value) : (arr, value) = > arr.some(el => el === value))();
contains(['foo','bar'],'baz');
Uncaught ReferenceError: Invalid left-hand side in assignment

箭头函数的符号 `=>`中间是不能有空格的

否则会出现下面的错误

 

Uncaught ReferenceError: Invalid left-hand side in assignment


posted @ 2016-11-23 10:10  Tome.Wong  阅读(141)  评论(0编辑  收藏  举报