Created
June 24, 2010 09:49
-
-
Save oogatta/451246 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
var a = 'global'; | |
Object.prototype.b = 'Object'; | |
function test1() { | |
console.log(a); | |
console.log(b); | |
} | |
function test2() { | |
var b = 'inner'; | |
(function(){ | |
console.log(a); | |
console.log(b); | |
})(); | |
} | |
test1(); | |
// global | |
// Object ← ココ注目。 test1AO.b >(AO は prototype がないので prototype チェーン探索はなし、スコープチェーンの次へ)> global(windows).b >>(window は prototype があるので prototype チェーン探索)>> window.__proto__.b = (new Object()).b の順で検索にいってる | |
test2() | |
// global | |
// inner ← AnonymousAO.b > test2AO.b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment