복붙노트

[JQUERY] jQuery.fn 무엇을 의미합니까?

JQUERY

jQuery.fn 무엇을 의미합니까?

해결법


  1. 1.jQuery를에, FN 속성은 프로토 타입 속성 단지의 별칭입니다.

    jQuery를에, FN 속성은 프로토 타입 속성 단지의 별칭입니다.

    JQuery와 식별자 (또는 $)는 단지 생성자 함수, 그것으로 만든 모든 인스턴스 생성자의 프로토 타입에서 상속입니다.

    간단한 생성자 함수 :

    function Test() {
      this.a = 'a';
    }
    Test.prototype.b = 'b';
    
    var test = new Test(); 
    test.a; // "a", own property
    test.b; // "b", inherited property
    

    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"
    

  2. 2.jQuery.fn는 jQuery.prototype에 대한 속기 정의된다. 소스 코드에서 :

    jQuery.fn는 jQuery.prototype에 대한 속기 정의된다. 소스 코드에서 :

    jQuery.fn = jQuery.prototype = {
        // ...
    }
    

    즉, jQuery.fn.jquery 현재의 jQuery 버전을 반환 jQuery.prototype.jquery, 별칭입니다. 다시 소스 코드에서 :

    // The current version of jQuery being used
    jquery: "@VERSION",
    

  3. 3.FN 그대로 JQuery와 프로토 타입을 말한다.

    FN 그대로 JQuery와 프로토 타입을 말한다.

    이 코드 행은 소스 코드입니다 :

    jQuery.fn = jQuery.prototype = {
     //list of functions available to the jQuery api
    }
    

    그러나 FN 뒤에 실제 도구는 jQuery를에 자신의 기능을 훅하는 가용성이다. 이 jQuery 오브젝트를 참조 할 수 있도록 그 JQuery와, 함수에 부모 범위 될 것입니다 기억하십시오.

    $.fn.myExtension = function(){
     var currentjQueryObject = this;
     //work with currentObject
     return this;//you can include this if you would like to support chaining
    };
    

    그래서 여기에 간단한 예입니다. 내가 어떤 색상이 개 확장, 파란색 경계를두고 다른 하나는 텍스트 파란색을 만들고 싶어, 나는 그들을 체인 싶은 말은 수 있습니다.

    $.fn.blueBorder = function(){
     this.each(function(){
      $(this).css("border","solid blue 2px");
     });
     return this;
    };
    $.fn.blueText = function(){
     this.each(function(){
      $(this).css("color","blue");
     });
     return this;
    };
    

    지금 당신은이 같은 클래스에 대하여 사람들을 사용할 수 있습니다 :

    $('.blue').blueBorder().blueText();
    

    (I이 가장 서로 다른 클래스 이름을 적용하기로 CSS로 수행 알고 있지만 명심하시기 바랍니다이 개념을 보여주기 위해 단지 데모입니다)

    이 답변은 전체 깃털 확장의 좋은 예있다.


  4. 4.JQuery와 소스 코드에서는 jQuery.fn = jQuery.prototype = {...} jQuery.prototype 개체이므로 jQuery.fn의 값은 단순히 동일한 객체에 대한 참조가있을 것이다 jQuery.prototype 이미 언급있다.

    JQuery와 소스 코드에서는 jQuery.fn = jQuery.prototype = {...} jQuery.prototype 개체이므로 jQuery.fn의 값은 단순히 동일한 객체에 대한 참조가있을 것이다 jQuery.prototype 이미 언급있다.

    즉 (가 않는)가 true 평가되면이를 확인하려면 다음가 같은 객체를 참조 jQuery.fn === jQuery.prototype를 확인하실 수 있습니다

  5. from https://stackoverflow.com/questions/4083351/what-does-jquery-fn-mean by cc-by-sa and MIT license