OK、それがどのように機能するかをもう一度説明しようと思います。Global
他のすべての「ルート」であるECMAScriptのオブジェクトがあります。ブラウザでは、window
オブジェクトはを実装しGlobal
ます。それで:
function assert( condition, message ) {
if ( !condition )
if ( typeof message != 'undefined' ) alert( message );
else alert( 'Free Consulting just talks rubbish' );
}
// assuming global scope
assert( this == window, 'noes!' ); // and Global context
var spam = 'for all you python lovers'; // becomes a property of Global
assert( spam == window.spam, 'there not much spam in it' ); // same
function eggs () { // becomes a method of Global actually
assert( spam == window.spam, 'shut up!' ); // unqualified spam available here through closure
assert( arguments.callee == window.eggs ); // and again
}
eggs();
結論夫人:JavaScriptは独自の特性を持つ別個の言語であるため、他の言語の知識をJSに適用しないでください(ダグラス・クロックフォードは悲しいパンダになります:)