zoukankan      html  css  js  c++  java
  • jquery 源码结构学习

    最近想要了解一下jquery 库是怎样实现的,源码结构如何。通过查看资料知道了,jquery源码整体结构如下所示,平时用到的例如$.ajax()形式的方法主要是通过jq.extend({})中定义的方法属性得到的,形如$("div").css()方法是通过jq.fn.extend({})拓展得到。

    (function(window,undefined){
    var jq = function(selector,content){
    return new jq.fn.init(selector,content,rootjq);
    },
    jq.fn = jq.prototype = {
    init:functin(selector,content,rootjq){};
    };
    jq.fn.init.prototype = jq.fn;

    jq.extend({
    // 可供jquery“类”使用的属性和方法,例如$.ajax(),同时可用在jq.fn.extend里面使用的
    // 属性和方法
    })

    jq.fn.extend({
    // jq对象具备的方法和属性,例如:$("div").css()
    removeDate:function(key) {
    return this.each(function(){
    jq.removeDate(this,key);
    });
    }
    css:function(name,value) {
    // ...
    }

    });

    function fn(){
    // 封装的函数,可用于内部使用。
    }

    if(typeof module==="object" && module && typeof module.exports === "object") {
    // 支持模块化的模式
    module.exports = jq;
    }else {
    window.jq = window.$ =jq;
    if(typeof define === "function" && define.amd) {
    define("jq",[],function(){
    return jq;
    });
    }
    }

    })(window)

    详细信息可参考:https://github.com/chokcoco/jQuery-

    https://www.cnblogs.com/xuxiuyu/p/5989743.html

    http://bbs.miaov.com/forum.php?mod=viewthread&tid=7385对理解jquery库的整体结构很有帮助。

  • 相关阅读:
    Android View 的绘制流程
    Android Studio 注释模板
    Flutter https://flutter.cn/docs学习之 工作原理
    Android 手机兼容差异
    Flutter plugin的两种方式
    本周总结
    mapreduce程序开发简单实例 WordCount
    《需求工程——软件建模与分析》阅读笔记之一
    本周总结
    本周总结
  • 原文地址:https://www.cnblogs.com/1833lljy/p/9478642.html
Copyright © 2011-2022 走看看