JQ核心骨架
(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 ) {
varjQuery = 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.fnjQuery.extend = jQuery.fn.extend = function() {//...
};jQuery.fn.extend({addClass: function( value ) {//...return this; //返回this,鏈式調用的秘密
}});window.jQuery = window.$ = jQuery;})( window );
?
轉載于:https://www.cnblogs.com/haohaoday/p/3336866.html
總結
- 上一篇: 卓普C2评测
- 下一篇: 关于Python中的self