Well, I will try to explain how this works again. There is an ECMAScript Global object that is the “root” of everything else. In window browsers, the object implements Global . So:
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();
Mrs Conclusion: JavaScript is a great language with its own specific features, so do not apply other language skills to JS (this makes Douglas Crockford a sad panda :)
source share