Objects and arrays-creating custom objects

Source: Internet
Author: User

————————————————————————————————

<script type= "Text/javascript" >
The simplest way to create objects, surrounded by a pair of curly braces.
var obj001 = {}; Use curly braces to create an object with empty content
OBJ001.PROP1 = 100; Add an attribute Prop1 to the object, assigning a value of 100
OBJ001.PROP2 = function () {//Adds a method prop2 for the object and provides an implementation
Alert (' I am Method 001 '); Provide an alert statement
};
OBJ001.PROP2 (); Methods for calling Objects
Create an object using function
function createObj002 () {//declares a function that creates an object, similar to the class
THIS.PROP1 = 200; Declares an attribute Prop1
THIS.PROP2 = function () {//Declare a method PROP2
Alert (' I am Method 002 ');//provide an alert statement
};
};
var obj002 = new createObj002 ();//Create a Obj002 object
OBJ002.PROP2 (); Call the Prop2 method of the Obj002 object
Create an object in the form of a new object ()
var obj003 = new Object ();
OBJ003.PROP1 = 300; Set Property Prop1
OBJ003.PROP2 = function () {//Adds a method prop3 for the object and provides an implementation
Alert (' I am method 003 '); Provide an alert statement
};
OBJ003.PROP2 (); Calling methods
</script>

——————————————————————————————————————

Objects and arrays-creating custom objects

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.