Three attribute instances of the array object

Source: Internet
Author: User

Length PropertyDefinition and usage

The length property can set or return the number of elements in the array. This is very common.

Grammar
Arrayobject.length
Prototype PropertyDefinition and Usage

The prototype property gives you the ability to add properties and methods to an object.

Grammar
Object.prototype.name=value
Example

In this example, we will show how to use the prototype property to add properties to an object:

  

1<script type= "Text/javascript" >2     //constructor Function3   functionEmployee (Name,job,born)4   {5    This. name=name;6    This. job=job;7    This. born=born;8   }9   //new instance, Bill, he inherits all the attributes of employeeTen  varBill=NewEmployee ("Bill Gates", "Engineer", 1985); One  //Add the Salary property to the employee prototype Aemployee.prototype.salary=NULL; -   //This property can be inherited by Bill to -bill.salary=20000; the   - document.write (bill.salary); -   -</script>

Output:

20000

Constructor property
The constructor property returns a reference to the array function that created this object.
<script type= "Text/javascript" > // constructor Function function Employee (Name,job,born) {this. name=name; this. job=job; this. born=born;} var bill=New employee ("Bill Gates", "Engineer", 1985);d Ocument.write (bill.constructor); </script>

Output:

1 function Employee (name, JobTitle, born) 2 {this this. Born = born;}

The result is that the constructor that created it is returned

Three attribute instances of the array object

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.