Discuss
/
JavaScript
/
Chrome哪个版本支持rest关键字?
Chrome哪个版本支持rest关键字?
Topic sourcechrome怎么会不支持呢?
直接在浏览器打开JavaScript控制台,输入:
> function f(...rest) { console.log(rest); }
undefined
> f(1, 2, 3)
[1, 2, 3]
廖老师啊确实有些chrome不支持rest关键字...比如我的,前面关于es6的测试都没问题不知道为什么在这里报 Uncaught SyntaxError: Unexpected token ...(…) 的错误...试了一下edge是可以的,大家用edge吧
不是不支持...rest,而是Chrome默认将一些JavaScript的新特性/实验性特性关闭了,可以在地址栏输入 chrome://flags/#enable-javascript-harmony 然后“启用实验性JavaScript”,重启Chrome之后就可以了使用...rest了。可参照: http://stackoverflow.com/questions/24008366/using-ecmascript-6
- 1
姜争辉_十一不哭
Chrome版本号:45.0.2454.99 m sum函数: function sum(...rest) { var count = 0; rest.forEach(function(element){ if(typeof element === 'number'){ count = count + element; } }); return count; } 无论怎么写,错误SyntaxError: Unexpected token ... 即使把下面评论别人写的粘贴后依然是这个错误