Pre-classification : $.extend ()--purpose: extension and inheritance
1. Object Extend ()
Extends another object with one or more objects and returns the original object that has been modified. This is a very useful utility for simple inheritance.
(1) Extension: (Extension of DOM element method)
① a single method extension notation:
$.fn.testfn=function (options) {
$.defaultoptions={
Name: "Li",
AGE:20,
Getname:function () {
return this.name;
}
var p=$.extend ($.defaultoptions,options| | {});
.
.
.
}
}
② several ways to expand the writing:
$.fn.extend ({
Testfn:function (options) {
$.defaultoptions={
Name: "Li",
AGE:20,
Getname:function () {
return this.name;
}
var p=$.extend ($.defaultoptions,options| | {});
.
.
.
},
Testfn1:function (options1) {
}
});
(2) Inheritance:
var person={
Name: "Li",
AGE:20,
Getname:function () {
return this.name;
}
}
var person1=$.extend ({},person);//person1 inherits the person
Person1.setage=function () {
this.age=33;
}
Person1.setage ();
Person1.sex= "Boy";
alert (person1.age+person1.sex);//33boy
Parsing: Person1 inherits the properties and methods of person owning person, and defines its own properties and methods based on it.
Practice:
Extend_test.js
Call:
Complete!
jquery Plugin Development format and parsing 3 $.extend () uses