This question already has answers here:
What's the meaning of “=>” (an arrow formed from equals & greater than) in JavaScript?
(13个回答)
4年前关闭。
我正在尝试构建butter(https://github.com/butterproject/butter-desktop),但由于hoek库中的代码而无法编译:
还有其他使用此“ operator”
我试图理解,我想它就像一个“函数”运算符...
如果我正确的话,类似于:
在第一个代码上:
在这种情况下与
和第二个代码:
任何人都可以确认并正式给我这个参考吗?
在线代码为:
https://github.com/hapijs/hoek/blob/master/lib/index.js#L483
(13个回答)
4年前关闭。
我正在尝试构建butter(https://github.com/butterproject/butter-desktop),但由于hoek库中的代码而无法编译:
/src/butter-desktop/node_modules/hawk/node_modules/hoek/lib/index.js:483
compare = (a, b) => a === b;
^
...
>> Unexpected token >
还有其他使用此“ operator”
=>
的行,例如: const leftovers = ref.replace(regex, ($0, $1) => {
const index = values.indexOf($1);
++matches[index];
return ''; // Remove from string
});
我试图理解,我想它就像一个“函数”运算符...
如果我正确的话,类似于:
在第一个代码上:
compare = (function(a, b) { return a === b; })(a,b);
在这种情况下与
compare = a === b;
和第二个代码:
const leftovers = ref.replace(regex, (function($0, $1) {
const index = values.indexOf($1);
++matches[index];
return ''; // Remove from string
})($0, $1));
任何人都可以确认并正式给我这个参考吗?
在线代码为:
https://github.com/hapijs/hoek/blob/master/lib/index.js#L483
最佳答案
这是arrow function。升级到Node.js 4.x,以便您可以使用这样的ES6功能。
关于javascript - JS:有一个新的运算符“=>” ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33597802/