jquery Plugin Development format and parsing 3 $.extend () uses

Source: Internet
Author: User

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

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.