What does the JavaScript new keyword do

Source: Internet
Author: User

Basic process

1. Create an empty object
2. The prototype of an empty object points to the prototype property of its constructor
3. Executes the constructor, and this of the constructor points to the object
4. Determine the return value type of the constructor, if it is a value type, returns the empty object itself, and if it is a reference type, returns the reference type

For example, create an instance of person

function Person (name,age) {    this. Name = name;      this. Age = Age ;} var obj == person.prototype; var result = Person.call (obj,name,age); if (typeof(Result) = = ' object ')    {= result;} Else {    = obj;} return person

What does the JavaScript new keyword do

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.