读书人

诡谲的Javascript

发布时间: 2012-10-28 09:54:44 作者: rapoo

诡异的Javascript
Javascript 不存在块层次的作用域。

var scope = "global";function f( ) {//这里引用的仍然是f内的scope,只是这个时候,变量 scope还未被赋值。    alert(scope);         // Displays "undefined", not "global"    var scope = "local";  // Variable initialized here, but defined everywhere    alert(scope);         // Displays "local"}f( );

读书人网 >JavaScript

热点推荐