Jquery.extend Study Notes

Source: Internet
Author: User

//
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.