jquery源码;是怎么实现直接调用$()函数原型上的方法的?1:当我们调用jQuery()方法时;就会先加载return new jQuery.prototype.init();此代码返回一个init()对象;属于jQuery()对象。jQuery.prototype.init.prototype=jQuery.prototype;这句话让初始化函数init()这个函数去继承jQuery原型上的方法;然后就能直接调用jQuery原型上的方法;;这是jquery的做法;

2;return new jQuery.prototype.init();这句代码做了两件事情;(1)执行初始化函数init();(2)返回一个init()对象;

3;jQuery.prototype.init.prototype=jQuery.prototype;这句话让init()对象指向了jQuery的原型;所以执行jQuery()函数时;返回的对象就可以调用jQuery原型上的方法;jQuery.prototype.init.prototype这里的jQuery是一个够着函数;。


jquery源码;是怎么实现直接调用$()函数原型上的方法的?

这是普通面向对对象的做法;