zoukankan      html  css  js  c++  java
  • 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 ) {
    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 );
  • 相关阅读:
    创建型模式
    建造者模式
    抽象工厂模式
    工厂方法模式
    原型模式
    [水]三个日常签到题
    [数]青蛙的约会&Strange function
    [水]三个数学的小技巧题
    Jquery Ajax的使用
    easyui学习记录:combotree的使用
  • 原文地址:https://www.cnblogs.com/haohaoday/p/3336866.html
Copyright © 2011-2022 走看看