jQuery provides two methods for developing plug-ins, namely:
jQuery.fn.extend(object);
jQuery.extend(object);
jQuery.extend(object); Extend the jQuery class itself. Add new methods to the class.
jQuery.fn.extend(object); Add methods to jQuery objects. This should be easy to understand. Give an example.
new soul
new soul
new soul
new soul
Okay, you also saw a little usage of $.extend() above.
1. Merge multiple objects.
What is used here is the function of nesting multiple objects of $.extend().
The so-called nesting of multiple objects is somewhat similar to the operation of merging arrays.
But here are the objects. Give examples.
//Usage: jQuery.extend(obj1,obj2,obj3,..)
var Css1={size: "10px",style: "oblique"}
var Css2={size: "12px ",style: "oblique",weight: "bolder"}
$.jQuery.extend(Css1,Css2)
//Result: The size attribute of Css1 is overwritten and the weight attribute of Css2 is inherited
// Css1 = {size: "12px", style: "oblique", weight: "bolder"}
2. Deeply nested objects.
jQuery.extend(
{ name: "John", location: { city: "Boston" } },
{ last: "Resig", location: { state: "MA" } }
);
// Result:
// => { name: “John”, last: “Resig”, location: { state: “MA” } }
// New and more in-depth .extend()
jQuery.extend( true,
{ name: "John", location: { city: "Boston" } },
{ last: "Resig", location: { state: "MA" } }
);
// result
// => { name: "John", last: "Resig",
// location: { city: "Boston" , state: "MA" } }
3. You can add static methods to jQuery.
html>