两个个关于javascript的scope的有趣的例证

两个个关于javascript的scope的有趣的例子// Scope insanity// a self-executing anonymous function(func

两个个关于javascript的scope的有趣的例子

// Scope insanity// a self-executing anonymous function(function() {  var baz = 1;  var bim = function() {    alert( baz );  };   bar = function() {    alert( baz );  }; })(); // baz is not defined outside of the functionconsole.log( baz ); // bar is defined outside of the anonymous function// because it wasn't declared with var; furthermore,// because it was defined in the same scope as baz,// it has access to baz even though other code// outside of the function does notbar(); // bim is not defined outside of the anonymous function,// so this will result in an errorbim();

?

?

来自jquery的教学课程:?http://learn.jquery.com/javascript-101/scope/