标签:ack 对象 div func 作用域 调用 定义 not query
----------------------------------------------------------------- cc = function(){alert(345)}, pushStack = function() { cc(); }, pushStack();//345 //没加var的放在window对象中 pushStack = function() { cc(); }, cc = function(){alert(345)}, pushStack();//345 ---------------------------------------------------------------- pushStack = function() { cc();//cc is not defined }; pushStack(); cc = function(){alert(345)}; pushStack = function() { cc(); }; pushStack();//345 function cc(){alert(345)}; ---------------------------------------------------------------- cc = function(){alert(345)}; pushStack();//pushStack is not defined ,js解析器执行到这里的时候pushStack还是未定义 pushStack = function() { cc(); }; cc = function(){alert(345)}; pushStack();//345,js解析器执行到这里的时候pushStack已经定义了 function pushStack() { cc(); };
name = ‘2‘; a = function(){ alert(this.name); alert(888); }, o = { fn1 : function(){ a = function(){ //fn1执行的时候(fn1要执行,不执行是加不进去的)把a加到window里面去,把外部的a方法覆盖了 alert(this.name);//2 window alert(this);//2 alert(666); }; a();//666 a.call(window) window.a();//666 } } o.fn1(); window.a();// 2 666
name = ‘2‘; a = function(){ alert(this.name); alert(888); }, o = { fn1 : function(){ this.a = function(){//fn1执行,给o对象加了a方法 alert(this.name); alert(this); alert(666); }; a(); //2 888 a.call(window) ,都是从window中找a()没有就报错 window.a(); //2 888 } } o.fn1(); window.a();// 2 888
o.a();//666
name = ‘2‘; a = function(){ alert(this.name); alert(888); }, o = { fn1 : function(){ var a = function(){ //fn1函数执行,就有2个a方法,一个在fn1局部作用域,一个在window alert(this.name); alert(this); alert(666); }; a(); //2 666 a.call(window),查找局部作用域的a方法 window.a(); // 2 888 } } o.fn1(); window.a();// 2 888
标签:ack 对象 div func 作用域 调用 定义 not query
原文地址:http://www.cnblogs.com/yaowen/p/6906343.html