javascript - JS 对象和数组的创建使用new和不使用new有什么区别呢?

查看:135
本文介绍了javascript - JS 对象和数组的创建使用new和不使用new有什么区别呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

比如:

var a = Array(); 和 var aa = new Array();

var b = Object(); 和 var bb  = new Object();

解决方案

根据EMACScript标准

The Array constructor is the %Array% intrinsic object and the initial value of the Array property of the global object. When called as a constructor it creates and initializes a new exotic Array object. When Array is called as a function rather than as a constructor, it also creates and initializes a new Array object. Thus the function call Array(…) is equivalent to the object creation expression new Array(…) with the same arguments.

调用Array()new Array()是等同的。

这篇关于javascript - JS 对象和数组的创建使用new和不使用new有什么区别呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆