希望有高人指点,里头的this分别指向谁,为什么结果是罗列出来的那些。。????????
var $=jQuery=function(){
return new jQuery.fn.init();//返回原型方法init();
}
jQuery.fn=jQuery.prototype={
init:function(){//在初始化原型方法中返回实例的引用
this.length=0;
this.test=function(){
return this.length;
};
return this;
},
jQuery:"1.3.2",
length:1,
size:function(){
return this.length;
}
};
alert($().jQuery);//返回undefined
alert($().test());//返回0
alert($().size());//抛出异常
var $=jQuery=function(){
return new jQuery.fn.init();//返回原型方法init();
}
jQuery.fn=jQuery.prototype={
init:function(){//在初始化原型方法中返回实例的引用
this.length=0;
this.test=function(){
return this.length;
};
return this;
},
jQuery:"1.3.2",
length:1,
size:function(){
return this.length;
}
};
alert($().jQuery);//返回undefined
alert($().test());//返回0
alert($().size());//抛出异常
length: 0,
test: function(){return this.length;}
}
$().JQuery,你看下上门的属性,有这个吗? 当然是undefined
$().test(); 调用test函数,返回length, 属性看看,是0对吗
alert($().size()): 属性中有size属性吗? 没有吧,你还把它作为一个方法调用,当然抛出函数异常。
jQuery.fn.init=jQuery.prototype上面的代码中$()返回的对象只是init对象,没有length jQuery size这些属性,加上上面的那句就有了这些属性
关于对象可以看一下http://blog.csdn.net/sencha_android/article/details/6699395这里面那张图片