Jquery $. FN $. FX
$. FN refers to the namespace of jquery. Adding Methods and attributes on FN will be effective for each jquery instance.
For example, extend $. FN. ABC (), that is, $. FN. ABC () is an extension of the ABC method for jquery, so every jquery instance can reference this method later.
Then you can: $ ("# Div"). ABC ();
Extends are usually used. For more information, see the API.
Jquery provides two methods for development plug-ins:
Jquery. FN. Extend (object );
Jquery. Extend (object );
Jquery. Extend (object); adds a new method to the class to extend the jquery class itself.
Jquery. FN. Extend (object); add a method to the jquery object.
What is fn. It is not difficult to see jquery code.
Jquery. fn = jquery. Prototype = {
Init: function (selector, context ){//....
//......
};
It turns out that jquery. fn = jquery. prototype. It is certainly no stranger to prototype.
Although JavaScript does not have a clear concept of a class, it is more convenient to use a class to understand it.
Jquery is a well-encapsulated class. For example, we use the statement $ ("# btn1") to generate a jquery class instance.
Jquery. Extend (object); adding class methods to the jquery class can be understood as adding static methods. For example:
$. Extend ({
Add: function (a, B) {return a + B ;}
});
Add a "static method" for jquery as add, and then you can use this method in the place where jquery is introduced,
$. Add (3, 4); // return 7
Jquery. FN. Extend (object); the extension to jquery. prototype is to add "member functions" to the jquery class ".Jquery class instances can use this "member function".
For example, we want to develop a plug-in and create a Special edit box. When it is clicked, the content in the current edit box of alert is displayed. You can do this:
JavaScript code
$. FN. Extend ({
Alertwhileclick: function (){
$ (This). Click (function (){
Alert ($ (this). Val ());
});
}
});
$ ("# Input1"). alertwhileclick (); // <input id = "input1" type = "text"/>
$ ("# Input1") is a jquery instance. When it calls the member method alertwhileclick, the extension is implemented. When it is clicked, the content in the current edit is displayed.