Skip to content

Instantly share code, notes, and snippets.

@oogatta
Created June 24, 2010 09:49
Show Gist options
  • Save oogatta/451246 to your computer and use it in GitHub Desktop.
Save oogatta/451246 to your computer and use it in GitHub Desktop.
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