//
Jquery.extend Study Notes
The Jquery.extend extension method is cleverly designed to dynamically add static methods and properties
Although there is a lot of information on the Internet, it is also a record of learning comprehension.
//
Define a person constructor
function Person (iname,iage) {
This.uname = Iname;
This.age = iage;
}
Defining a prototype method
Person.prototype = {
Shown:function () {
Calling a static method
Person.showname (this);
},
Showa:function () {
Calling a static method
Person.showage (this);
}
}
//
Here are two important ways to see the main
//
//
1. Extension functions
Two parameters: obj is a pair image parameter, prop property parameter
The obj value is generally {Key:value} similar to JSON format
//
Person.extend = function (Obj,prop) {
If the prop attribute parameter is not
if (!prop) {
Prop = obj;//will be a list of image functions
obj = this; obj is a pointer to the class that called it
}
Assign the function that you want to extend to the pair like person to which obj points
for (var i in prop) {
Console.log (Prop[i]);
Obj[i] = Prop[i];
Console.log (Obj[i]);
}
Console.log (obj, prop);
return obj;
};
2. Calling extended static functions
parameter is a pair of images (that is, a list of extended functions and attributes)
Person.extend ({
Person: "v1.0",
Defining static Methods ShowName
Showname:function (obj) {
Alert ("Uname=" + obj.uname);
}
,
Defining static Methods Showage
Showage:function (obj) {
Alert ("age=" + obj.age);
},
You can add more extension function methods here.
});
//=========================================================
For testing
var p = new Person ("Hello Dream", 30);
P.shown ();
P.showa ();
Jquery.extend Learning Notes