実行コンテキスト | 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
の評価結果。