Use of JavaScript objects

Source: Internet
Author: User

1. Create an Object

1). Use {}
The object also has the object var obj = {name: "Arilife", Age:26,birthday:new Date (1984, 4, 5), addr: {street: "Huang Quan Road", Xno: "13 5 ",  //attribute Getstreet:function () {return This.street}//Method}};alert (Obj.addr.street); alert (Obj.addr.getStreet ());


2). New constructor created

A. The system's

var obj = new Object (); obj.name = "Chow Tai Fook"; obj.age = 21;obj.getage = function () {return This.age};alert (Obj.getage ());

B. A custom

function person (name, age) {this.name = Name;this.age = Age;this.getage = function () {return this.age};} Window. Person ("jeery", +), var p = new Person ("Tom", 23);

2. Understanding of related Concepts 1). Object:

L JavaScript objects are actually collections of attributes, deterministic, unordered, and cross-specific

var o = {      p1:3,      p2:function () {alert ("---");},      p3: [1, "abc"],      P4: {t: "AA"},      p1: "Xfzhang"};
alert (O.P1);//teacher

Overwrite the original P1, because the object's cross-specific characteristics

2). Properties of the object:

L can be dynamically added and deleted, and its value can point to any type of data

O.name = "Terry";d elete O.p1;//alert (o.name);//terry//alert (O.P1); Undefined





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use of JavaScript 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.