What does jQuery.fn mean?

Posted chucklu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了What does jQuery.fn mean?相关的知识,希望对你有一定的参考价值。

n jQuery, the fn property is just an alias to the prototype property.

The jQuery identifier (or $) is just a constructor function, and all instances created with it, inherit from the constructor‘s prototype.

A simple constructor function:

function Test() {
  this.a = ‘a‘;
}
Test.prototype.b = ‘b‘;

var test = new Test(); 
test.a; // "a", own property
test.b; // "b", inherited property

 

A simple structure that resembles the architecture of jQuery:

(function() {
  var foo = function(arg) { // core constructor
    // ensure to use the `new` operator
    if (!(this instanceof foo))
      return new foo(arg);
    // store an argument for this example
    this.myArg = arg;
    //..
  };

  // create `fn` alias to `prototype` property
  foo.fn = foo.prototype = {
    init: function () {/*...*/}
    //...
  };

  // expose the library
  window.foo = foo;
})();

// Extension:

foo.fn.myPlugin = function () {
  alert(this.myArg);
  return this; // return `this` for chainability
};

foo("bar").myPlugin(); // alerts "bar"

 

以上是关于What does jQuery.fn mean?的主要内容,如果未能解决你的问题,请参考以下文章

What does it mean window.property in js?

Helix, what does it mean for Sitecore CMS development?

What does "size" in int(size) of MySQL mean?

(译)What does explicit keyword mean?

What does axis/axes mean in Numpy

空间复杂度是什么?What does ‘Space Complexity’ mean? ------geeksforgeeks 翻译