Skip to content

Instantly share code, notes, and snippets.

@azu
Created January 4, 2018 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azu/ca9d5a0f4b7c137bc5e2453f8783bf8c to your computer and use it in GitHub Desktop.
Save azu/ca9d5a0f4b7c137bc5e2453f8783bf8c to your computer and use it in GitHub Desktop.
実行コンテキスト 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