我想了解正常函数与箭头函数的行为.
箭头功能:
function arrowFunc() {
return () => arguments
}
console.log(arrowFunc(1, 2, 3)(1))Run Code Online (Sandbox Code Playgroud)
正常功能
function normalFunc() {
return function() {
return arguments
}
}
console.log(normalFunc(1, 2, 3)(1))Run Code Online (Sandbox Code Playgroud)
两个结果都是相同的,但看起来像上面定义的arrowFunc考虑第一个arg列表,其中normalFunc考虑第二组arg列表.
还尝试了babel-compilation来理解差异,但看起来行为有所不同,如下图所示:
通天输出:
"use strict";
function arrowFunc() {
var _arguments = arguments;
return function() {
return _arguments;
};
}
console.log(arrowFunc(1, 2, 3)(1));
function normalFunc() {
return function() {
return arguments;
};
}
console.log(normalFunc(1, 2, 3)(1));Run Code Online (Sandbox Code Playgroud)