优艾设计网

不使用new关键字创建Object对象为什么constructor有值??

优艾设计网 https://www.uibq.com 2023-04-15 11:10 出处:网络 作者:PS百科
var a1 = Object(); va优艾设计网_Photoshop百科r a2 = new Object(); console.log(a1); console.log(a1.constructor); console.log(a2.constructor);var Person = function(){ this.name = \"张三\" } var b1 = new

var a1 = Object(); va优艾设计网_Photoshop百科r a2 = new Object(); console.log(a1); console.log(a1.constructor); console.log(a2.constructor);var Person = function(){ this.name = "张三" } var b1 = new Person(); var b2 = Person(); console.log(b1.constructor); console.log(b2.constructor);// 出错

由于b2没有使用new操作符,那么他的constructor == undefined。

从理论上讲,a1.constructor也没有定义,但其可以正常返回值,为什么?
与一切对象都继承自Object有关么?


无料丶 2022-06-02 18:34优艾设计网_设计

When called in a non-constructor context, Object behaves identically to new Object().


0

精彩评论

暂无评论...
验证码 换一张
取 消