https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/arrow_functions
アロー関数は、this の値をレキシカルに束縛します。
function Person() {
// Person() のコンストラクターは自分自身を `this` として定義します。
this.age = 0;
setInterval(function growUp() {
// 非strict モードでは、growUp() 関数は `this` を Person() コンストラクターで定義された `this` とは違い、グローバル オブジェクトとして定義します。
this.age++;
}, 1000);
}arguments も this と同じようにレキシカルに束縛される。
https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/
Because ‘arguments’ is also lexically bound like ‘this’
f = () => console.log(arguments);
f(); // undefined
ff = function() { console.log(arguments); }
f(); // arguments {}
f = function(getArgsList){
getArgsList.forEach( (n) => console.log( arguments[n] ) ); // このコードは期待通りに動作する
}
f([2,4,6], "a1","a2","a3","a4","a5","a6","a7"); // "a2","a4","a6" ……が出力される