首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

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

2013-03-06 
两个个关于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/

热点排行