-----------------------------------------------------------------
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
jQuery = function() {
alert(1);
return new jQuery.fn.init();
},
jQuery.fn = jQuery.prototype = {//fn是类的静态属性
//能够调用jQuery原型里(constructor()、pushStack())方法的只能是jQuery对象或者init对象:$('div')。
constructor: jQuery,
init: function() {
},
//$('div').pushStack,this是$('div'),
pushStack: function() {
alert(2);
this.constructor();//1, this是init对象或者jQuery对象$('div'),返回的是新的空init对象
constructor();//constructor.call(window),调不了报错,
},
}
jQuery.fn.init.prototype = jQuery.fn;
var j = constructor();//window调用不了
$('div').pushStack();//1,2,1, $('div')是init对象可以调用pushStack()方法
o = {}
o.pushStack();//o.pushStack is not a function,能够调用pushStack方法是jQuery的对象后者init对象,
new jQuery.fn.init().pushStack();//2 1