Skip to content

[js] 第43天 JQuery的源码看过吗?能不能简单概括一下它的实现原理? #163

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

第43天 JQuery的源码看过吗?能不能简单概括一下它的实现原理?

Activity

cleverboy32

cleverboy32 commented on May 29, 2019

@cleverboy32

没看过。
猜测是 一个对象,上面集成了各种 api. 最后导出这个对象为 $ 符号使用。

tzjoke

tzjoke commented on May 31, 2019

@tzjoke

匿名函数。。

myprelude

myprelude commented on Jun 13, 2019

@myprelude

粗略的看过一点点

(function(window,undefined,document){
  function jQuery(prop){
    return new jQuery.prototype.init()
  }
  jQuery.prototype = {
    contructor:jQuery,
    init:function(prop){},
    //  ...
 }
 jQuery.prototype.init.prototype = jQuery.prototype;
 window['jQuery'] = window['$'] = new jQuery()
})(window,undefined,document)

jQuery是通过封装浏览器原生的DOM API实现dom元素的选取,然后封装到jQuery对象中去,同时根据浏览器检测对不同浏览器操作不同的APi .jQuery 对象上高度集成了超的API。当然 jQuery 还有做的更多比如,我们可以new jQuery('div'),也可以直接$('div'),这个巧妙地运算就是上面init方法;如果页面已经有$时,jQuery会先将$接管把之前$的全局名保存下来 等后面使用是在释放、。。。大致了解。

jiamianmao

jiamianmao commented on Aug 10, 2019

@jiamianmao

单例 + 链式调用

smile-2008

smile-2008 commented on Nov 4, 2020

@smile-2008

粗略的看过一点点

(function(window,undefined,document){
  function jQuery(prop){
    return new jQuery.prototype.init()
  }
  jQuery.prototype = {
    contructor:jQuery,
    init:function(prop){},
    //  ...
 }
 jQuery.prototype.init.prototype = jQuery.prototype;
 window['jQuery'] = window['$'] = new jQuery()
})(window,undefined,document)

jQuery是通过封装浏览器原生的DOM API实现dom元素的选取,然后封装到jQuery对象中去,同时根据浏览器检测对不同浏览器操作不同的APi .jQuery 对象上高度集成了超的API。当然 jQuery 还有做的更多比如,我们可以new jQuery('div'),也可以直接$('div'),这个巧妙地运算就是上面init方法;如果页面已经有$时,jQuery会先将$接管把之前$的全局名保存下来 等后面使用是在释放、。。。大致了解。

xiaoqiangz

xiaoqiangz commented on Jun 6, 2022

@xiaoqiangz

粗略的看过一点点

(function(window,undefined,document){
  function jQuery(prop){
    return new jQuery.prototype.init()
  }
  jQuery.prototype = {
    contructor:jQuery,
    init:function(prop){},
    //  ...
 }
 jQuery.prototype.init.prototype = jQuery.prototype;
 window['jQuery'] = window['$'] = new jQuery()
})(window,undefined,document)

jQuery是通过封装浏览器原生的DOM API实现dom元素的选取,然后封装到jQuery对象中去,同时根据浏览器检测对不同浏览器操作不同的APi .jQuery 对象上高度集成了超的API。当然 jQuery 还有做的更多比如,我们可以new jQuery('div'),也可以直接这个巧妙地运算就是上面方法;如果页面已经有(′div′),这个巧妙地运算就是上面init方法;如果页面已经有时,jQuery会先将接管把之前接管把之前的全局名保存下来 等后面使用是在释放、。。。大致了解。

mark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    jsJavaScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @smile-2008@haizhilin2013@xiaoqiangz@cleverboy32@jiamianmao

        Issue actions

          [js] 第43天 JQuery的源码看过吗?能不能简单概括一下它的实现原理? · Issue #163 · haizlin/fe-interview