【发布时间】:2018-04-23 16:25:41
【问题描述】:
var peopleFactory = function(name, age, height) {
var temp = {};
this.name = name;
this.age = age;
this.height = height;
temp.printPerson = function() {
console.log(this.name + '' + this.age + '' + this.height);
document.write(this.name + '' + this.age + '' + this.height);
};
return temp;
};
var person1 = peopleFactory('tanmay', 27, 5.11);
var person2 = peopleFactory('chinmay', 37, 5.12);
person1.printPerson();
person2.printPerson();
【问题讨论】:
-
您好,欢迎来到 Stack Overflow!请使用tour 并通读help center,尤其是How do I ask a good question? 做你的研究,search 以获取有关 SO 的相关主题,然后试一试。如果您在进行更多研究和搜索后卡住并且无法解开,请发布您的尝试minimal reproducible example,并具体说明您卡在哪里。人们会很乐意提供帮助。祝你好运!
-
this.name = name;应该是temp.name = name;... 而其他的也是。
标签: javascript design-patterns factory