核心提示:1,字面量的方式创建对象;var obj = { name: edison,age: 100,sayHi: function () { console.log( 汪汪汪~); }}2,调用构造函数创建...
1,字面量的方式创建对象;
var obj = { name: edison, age: 100, sayHi: function () { console.log(" 汪汪汪~"); } }
2,调用构造函数创建对象;
var obj2 = new Object(); //调用系统的构造函数创建 obj2.name= edison; obj2.age= 100; obj2.sayHi= function () { console.log(" 汪汪汪~"); };
3,自定义构造函数创建对象;
function Person( age, sex ) { this.age = age; this.sex = sex; this.sayHi = function () { console.log("嘎嘎嘎嘎~");}; }