今天跑去又看了一下jq的源码。然后写了个简化的版本
//使用立即执行函数封闭作用域,使外界不能访问里面的参数。
(function(){
var myQuery
// 返回的是一个对象实例
myQuery =function(){
return new myQuery.prototype.xxx()
}
//把方法写在myQuery 的原型上
myQuery.prototype ={
xxx : function (){
return this ; // return this 后,可以使用原型链调用
}
}
window.$=window.myQuery=myQuery //把myQuery暴露给外界的window上
var xxx =myQuery.prototype.xxx(); //让myQuery原型上的xxx方法的原型默认指向的是object,
xxx.prototype = myQuery.prototype //让xxx的原型指向变成myQuery ,这样方便后面的链式调用。
}())