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评测
- 下一篇: IOS7开发~API变化