$.extend (obj); to extend the jquery itself, add a new method to the class
$.fn.extend (obj); Adds a method to a jquery object.
such as (1):
$.extend ({ add:function(b) { return +b; } }) $.add (//return
Note that there is no direct call on this side of the call, without any objects in front. Direct $.+ Method Name
(2):
$.fn.extend ({clickwhile: function () {$ ( this ). Click (function this
). val ())})}) $ (
' input '). Clickwhile (); //
Note that there are objects in front of the call. That is $ (' input ') such a thing.
describes their essential differences before, and now specifically describes their respective details
actually $.extend () has two ways of writing
(1) $.extend (obj);
This is only one parameter, which means: Adding a class method to the jquery class can be understood as adding a static method, which is the global method.
(2) $.extend (target, object1, object2, object3, object4,[objectn]);
This is two or more than two arguments that represent the meaning of extending an object with one or more other objects, returning the extended object. That is, the first object is expanded and overwritten.
(function ($) { var aaa={name: ' 1 ', Age: ' + ', Sex: ' NV '}; var bbb={name: ' 2 ', Age: ' + '}; var ccc = $.extend (AAA, BBB); alert (ccc.sex); // NV alert (aaa.name); // 2 }) (JQuery);
I wonder if you have seen $.extend ({}, AAA, BBB) with {}? Take a look below
(function ($) { var aaa={name: ' 1 ', Age: ' + ', Sex: ' NV '}; var bbb={name: ' 2 ', Age: ' + '}; var ccc = $.extend ({}, AAA, BBB); alert (ccc.sex); // NV alert (aaa.name); // 1 }) (JQuery);
Why are alert (aaa.name) different results? If you knew, you wouldn't have to look down.
This is because: when multiple object parameters are merged, the structure of the first object is destroyed, so you can pass an empty object as the first argument
$.fn.extend (obj);
What does the FN in $.fn mean?
Actually is prototype, namely $.FN=$.PROTOYTPE;
If you know the prototype, you'll see what he means.
JQuery's $.extend and $.fn.extend roles and differences, and some of their small details