【问题标题】:What's the purpose of jQuery.fn [duplicate]jQuery.fn 的目的是什么 [重复]
【发布时间】:2012-01-31 16:44:25
【问题描述】:

可能重复:
What does jQuery.fn mean?

部分jQuery源代码说明:

jQuery.fn = jQuery.prototype = {

考虑到这一点,不会

$.fn.adamPlugin = function(options) {  
   return this.each(function() {   });  
};

等同于

$.prototype.adamPlugin = function(options) {  
   return this.each(function() {   });  
};  

如果是这样,$.fn 的意义何在?在 JavaScript 中向原型添加东西是相当普遍的,所以我不太明白为什么 jQuery 的人会尝试将其抽象掉。

【问题讨论】:

  • 我认为速记可以让他们使图书馆更小......而且,我听说他们是少写的大力支持者。
  • 为什么要为 jQuery 使用 $?用另一个替换一个也是相同的。
  • Paul Irish 也解释了一点 here
  • @antisanity:大概就是这样。此外,压缩器无法重命名 prototype 属性,因为它是一个特殊名称,但它可以重命名 fn
  • @antisanity - 就是这样。它使库大小更小,并且对缩小器更友好。你能在这个问题结束之前把它作为答案吗?

标签: javascript jquery


【解决方案1】:

这只是prototype 的方便别名而已。

【讨论】:

    猜你喜欢
    • 2011-05-04
    • 1970-01-01
    • 2019-04-24
    • 2013-05-21
    • 1970-01-01
    • 1970-01-01
    • 2010-12-17
    • 2011-12-02
    • 2015-09-10
    相关资源
    最近更新 更多