Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
haizhilin2013 opened this issue May 28, 2019 · 6 comments
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

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

@haizhilin2013 haizhilin2013 added the js JavaScript label May 28, 2019
@cleverboy32
Copy link

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

@tzjoke
Copy link

tzjoke commented May 31, 2019

匿名函数。。

@myprelude
Copy link

粗略的看过一点点

(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
Copy link

单例 + 链式调用

@MrZ2019
Copy link

MrZ2019 commented Nov 4, 2020

粗略的看过一点点

(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
Copy link

粗略的看过一点点

(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
Labels
js JavaScript
Projects
None yet
Development

No branches or pull requests

7 participants