优艾设计网

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

优艾设计网 https://www.uibq.com 2023-04-22 20:52 出处:网络 作者:PS入门教程
var a1 = Object(); var 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 = Pers

var a1 = Object(); var 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.co优艾设计网_设计客nstructor); console.log(b2.constructor);// 出错

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

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


纆g 2022-08-15 16:46

优艾设计网_在线设计

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


0

精彩评论

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