What is a $.fn object?

This site > I found that if you put your own method in $.fn object, you can create your own plugin.
I don't know how to capture the sudden $.fn object.

Does the $.fn object match the image like a jQuery base class?

console.log (jQuery === $);// true;
  console.log (jQuery.fn === $.fn);// true;
  console.log (jQuery.prototype === jQuery.fn);// true;
  console.log (jQuery.prototype === $.fn);// true;
  console.log ($. prototype === $.fn);// true;

In JavaScript, all objects are created based on "prototypes".
In other words, there is a minimal template called "prototype", and it is an image that creates a new object by referring to it.
$.fn object is equivalent to $.prototype (jQuery.prototype) and is the minimum template of jQuery.
By the way, $is a jQuery rewrite.


  • Answer # 1


    jQuery ()andnew jQueryare equivalent.

    jQuery.prototype === jQuery.fn
    Minimum template

    In other words, is the $.fn object the minimum template for jQuery?

    I was reading with the thought of "What is a minimal template?" Was it the term written at https://www.sejuku.net/blog/47722?
    I think this is not a programming term, but a term originally invented by the author.
    It ’s not a word used to explain to others.

    It is not wrong to compare it to a template in the sense that it is a template for a generated object, but if it is called a "minimum template" by extension, the object at the top of the prototype chain Sounds like pointing.
    (In the first place, it is written as "prototype" from the beginning in the sense of a template, so there is no need to bother to change it to "template")

    new jQuerytemplate isjQuery.prototype

    new jQuery'sminimal templateisObject.prototype

    However, the illustrations are just illustrations, not essences.
    Even if we take the model of a template, the "property model" can be put into essence.
    If you strictly redefine the "example", it will no longer be an "example".
    In other words, it is an "example" that blurs various concepts vaguely.

    Understand theprototype chainfirst, with an illustration.
    If you understand that much, you can understand the rest.


    In other words, there is a minimal template called a "prototype", and it is an image that creates a new object by copying it.

    You are not copying.Browse.

    Re: tkshp

  • Answer # 2

    You can add a method to a jQuery object
    For example:

    $.fn.myFunc = function (x) {$(this) .val (x);}
    $(function () {
      $('# btn'). on ('click', function () {
        $(this) .myFunc ("fuga");
    <input type = "button" id = "btn" value = "hoge">