(function (window) {
var jQuery = function(selector) {
return new jQuery.fn.init(selector);
}
jQuery.fn = {
html: function(){
},
css: function(){
}
};
var init = jQuery.fn.init = function(selector){
var slice - Array.prototype.slice;
var dom = slice.call(document.querySelectorAll(selector));
var i, len = dom ? dom.length : 0;
for (i = 0; i < len; i++){
this[i] = dom[i];
}
this.length = len;
this.selector = selector || '';
}
init.prototype = jQuery.fn;
window.$ = jQuery;
})(window)
//为什么要把原型方法放在$.fn?
// 1、只有$会暴露在window全局变量
// 2、将插件扩展统一到$.fn.
网友评论