Use constructors to define "range classes"

Source: Internet
Author: User

Usage 1:

Bytes --------------------------------------------------------------------------------------------------------------

<SCRIPT>

// This is a constructor used to initialize the newly created "range object"

// Note that no object is created and an object is returned, only Initialization

Statement 1:

Function a (x ){

This. f = X;

}

Statement 2:

VaR A = function (){};

// All range objects are inherited from this object

// Note that the attribute name must be prototype.

A. Prototype = {

Add: function (y ){

Return number (this. f) + number (y );

}

};

// New A () creates a range object

X = new A (10). Add (8 );

?

Console. Log (x); // output: 18

</SCRIPT>

?

Usage 2:

Bytes --------------------------------------------------------------------------------------------------------------

<SCRIPT>

VaR A = function (x) {This. x = x ;};

A. Prototype = {

Add: function (y ){

Return this. x = This. x + number (y );

}

};

?

A. Prototype. Includes = function (){

???? Return this. x * 2;

}

?

_ Q = new;

_ Q. x = 50;

Console. Log (_ q. Events des ());

?

</SCRIPT>

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.