Created
November 4, 2016 15:05
-
-
Save kdnk/4c0027f481e6560c6e50bad91c588a5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaScript O'reilly | |
// スコープチェーン | |
// 関数が定義されたときに、現在有効なスコープチェーンを保存しておく。 | |
// 関数が呼び出されたときに、新たにオブジェクトを生成し、ローカル変数を保存。 | |
// 新たに生成されたオブジェクトをスコープチェーンに追加し、新たなスコープチェーンを生成。 | |
// 入れ子の場合は、外側の関数が呼び出されるたびに内側の関数が再び定義される。 | |
// そのため、外側の関数の呼び出しごとに、スコープチェーンがことなる。 | |
var scope = 'global' | |
function fn () { | |
var scope = 'local' | |
function f() { | |
console.log(scope) | |
} | |
return f | |
} | |
// need understandiing about "scope chain" | |
fn()() // local |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment