1、看jquery源码中创建的jquery构造函数后直接去返回new初始化方法,我把他写成下面这样报$.show is not a function错,下面这段代码有什么问题?
2、还有就是对象下面的方法是不是对象??
var jQuery=function(){
return new jQuery.prototype.init();
}
jQuery.prototype.init=function(){
this.show();
};
jQuery.prototype.show=function(){
alert("hello");
}
jQuery.prototype.init.prototype=jQuery.prototype;
window.$=jQuery;
$.show();
init
是构造器构造器的返回结果才是实例对象
实例对象才可以顺着原型链找到构造函数的
prototype
对象里定义的方法所以你自己看看
init
的方法,你确定那时候this
能访问到show
方法?如果你不能理解,请在
init
方法里把this
打印出来看看。另外第二个问题,方法实质上就是函数,函数是对象无疑。