ES6参数解构

时间:2016-04-26 05:06:09

标签: javascript node.js ecmascript-6

在我的代码中,这有效:

storedResponse.headers.forEach(function(header){
            response.setHeader(header.name, header.value)
        });

虽然失败了:

storedResponse.headers.forEach(function({name,value}){
            response.setHeader(name, value)
        });

这与第2.5节相同:http://www.2ality.com/2015/01/es6-destructuring.html。关于我在这里做错了什么的指示?

我在节点4.2.4下运行它(来自节点--version)。错误消息是:

/usr/local/bin/node --debug-brk=50852 server.js
Debugger listening on port 50852
/Users/shasn/WebstormProjects/Yama/server.js:22
        storedResponse.headers.forEach(({word, count}) => {
                                        ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.runMain [as _onTimeout] (module.js:467:10)
    at Timer.listOnTimeout (timers.js:92:15)

Process finished with exit code 1

0 个答案:

没有答案