WechatIMG2.png
var duelist = {
name: "武藤游戏",
age: 16,
gender: "男",
sayHi: function () {
console.log("你好,我的名字是 " + this.name);
},
};
var duelist = new Object();
(duelist.name = "阿图姆"),
(duelist.age = 3000),
(duelist.gender = "男"),
(duelist.sayHi = function () {
console.log("你好,我的名字是 " + this.name);
});
function createDuelist(name, age, gender) {
var duelist = new Object();
duelist.name = name;
duelist.age = age;
duelist.gender = gender;
duelist.sayHi = function () {
console.log("你好,我的名字是 " + this.name);
};
return duelist;
}
var d1 = createDuelist("武藤游戏", 16, "男");
var d2 = createDuelist("阿图姆", 3000, "男");
function Duelist(name, age, gender) {
this.name = name;
this.age = age;
this.gender = gender;
this.sayHi = function () {
console.log("你好,我的名字是 " + this.name);
};
}
var d1 = new Duelist("武藤游戏", 16, "男");
var d2 = new Duelist("阿图姆", 3000, "男");
|
创建对象方式 |
return 语句 |
调用方式 |
工厂函数 |
函数内部创建 |
有 |
赋值调用 |
构造函数 |
赋值 this 对象 |
无 |
实例化调用 |
网友评论