(function(){ var jQuery = function(id){ return new _jquery(id); }; var _jquery = function(id){ //此处各种选择分支神马的都忽略~ this[0] = document.getElementById(id); this.length = 1; }; jQuery.fn = jQuery.prototype = { constructor: jQuery, addClass: function(className){ this[0].className += ' ' + className; } }; _jquery.prototype = jQuery.fn; window.$ = window.jQuery = jQuery; })();
(function( window, undefined ) { var jQuery = function( selector, context ) { // The jQuery object is actually just the init constructor 'enhanced' return new jQuery.fn.init( selector, context, rootjQuery ); }; //各种原型属性 jQuery.fn = jQuery.prototype = { constructor: jQuery, init: function( selector, context, rootjQuery ) { //... }, ... }; jQuery.fn.init.prototype = jQuery.fn; //extend方法,用来扩展jQuery,或jQuery.fn jQuery.extend = jQuery.fn.extend = function() { //... }; jQuery.fn.extend({ addClass: function( value ) { //... return this; //返回this,链式调用的秘密 } }); window.jQuery = window.$ = jQuery; })( window );