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.constructor); console.log(b2.constructor);// 出错
由于b2没有使用new操作符,那么他的constructor == undefined。
从理论上讲,a1.constructor也没有定义,但其可以正常返回值,为什么?
与一切对象都继承自Object有关么?
When called in a non-constructor context, Object behaves identically to new Object().
一周热门 更多>