Mozilla ドキュメントに関する ES6 アロー関数のドキュメントを調べているときに、アロー関数は、リンクで説明されているものを除いて、厳密モードのすべてのルールを適用することを知りました。
var f = () => { 'use strict'; return this};
var g = function () { 'use strict'; return this;}
console.log(f()); //prints Window
console.log(g()); // prints undefined
//we can test this in firefox!
しかし、Babel.js
アロー関数コードを ES5 コードにトランスパイルして、 (デモ リンク)undefined
ではなく返すWindow
"use strict";
setTimeout(function () {
return undefined;
}, 100);
したがって、上記のスニペットは Babel.js からの出力です。以下の出力ではありませんか?
"use strict";
setTimeout(function () {
return this;
}.bind(Window), 100);
私が ES6 を書いているなら、Window
それundefined
はバグですか?
または、私は何かを誤解しましたか?