Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
実行コンテキスト strict mode コード thisの評価結果
Script NO this ???
Script NO const fn = () => this ???
Script NO const fn = function(){ return this; } ???
Script YES this ???
Script YES const fn = () => this ???
Script YES const fn = function(){ return this; } ???
Module YES this ???
Module YES const fn = () => this ???
Module YES const fn = function(){ return this; } ???
const obj = { method(){ return this; } } ???
const obj = { method: function(){ return this; } } ???
Script const obj = { method: () => { return this; } } ???
Module const obj = { method: () => { return this; } } ???

はどの場合でも結果に影響しないということを示します。

関数はfn()と実行した場合のthisの評価結果、メソッドはobj.method()と実行した場合のthisの評価結果。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment