//通过字面量创建对象
var obj = {};
//通过new Object()创建对象
var obj2 = new Object();
//通过构造函数创建对象
function Test(num1, num2) {
this.n1 = num1;
this.n2 = num2;
};
var obj3 = new Test(3, 4);
//(构造函数名 instanceof 对象名)
//通过instanceof检测某个对象是否由指定构造器构造的
console.log(obj3 instanceof Test);
//对象名.create 创建对象
var obj4 = Object.create(Object.prototype);
var obj5 = Object.create(null);
var obj6 = Object.create({
x: 1
});
网友评论