JS Object-oriented

Source: Internet
Author: User

First, how to create an object

1.new Object ();

2.var a={};

3. Use the function to build the object as follows:

3. Constructor creates object function    person  () {        this.name= "Zhang Dan";        this.age=26;        this.gender= "female";    }    var p=new person ();//Create a new object that inherits all the properties of the template person ()     p.height=160;    Console.log (Person.prototype)//Only function has prototype, entity No, here print out or an object

 

Second, what is the object

var obj=new Object ();    Console.log (obj)

In the browser print out is as follows:

__proto__:object This is a prototype object. This property is not supported by all browsers. all objects whose final top-level objects are object. A prototype object is also an object.

Third, scope

Global variables, local variables

For example:

var a=100;//global Variables

function Test () {

var a=11;//local Variables

JS Object-oriented

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.