JS new Instance Tutorial

Source: Internet
Author: User

the var x = new Object () is not necessarily created with new, and I'm not sure.
x.__proto__ = A.prototype
var result = A.call (x)
if (typeof (Result) = = "Object") {
return result;
}
return x;


Constructor property of an object

Let's take a look at the first question left in the previous article.

function Base () {}base.prototype.a = 1var base = new base (); function derived () {}derived.prototype = Base;var d = new Derived ()


, new is the idea of creating an object. So which of the web effects can be new? Please see:

1>var i = new number (' 1 ');
2>var B = New Boolean (true);
3>var s = new string (' a ');
4>var f = new function (' alert (1); ');
5>var obj = new object;//var obj = new Object ();
6>var temp = function (A, B)
{
THIS.A = A;
this.b = b;
}
var t = new temp;

In these 6 cases typeof i,typeof b,typeof s,typeof f,typeof obj,typeof t return the ' object ' string of JS.

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.