我被困在Codewars.com的Javascript挑战中。它看起来是一个构造函数(?)函数,我认为我知道,但唉,不。 我在MDN和其他地方寻找例子。 我宁愿知道错误的观点而不是直截了当的答案,看看我能否认出我自己。 挑战:Codewars构造函数
function new Person(name){
this.name = name;
return name;
}
Person.prototype.greet = function(otherName){
return "Hi " + otherName + ", my name is " + name;
};
通过做一些研究,我想也许增加了构造的两个名字会做,但再次得到一个“意外的标记新”的错误。我尝试:
function new Person(name, otherName){
this.name = name;
this.otherName = otherName;
return name + " " + otherName;
}
Person.prototype.greet = function(otherName){
return "Hi " + otherName + ", my name is " + name;
};
var fullName = new Person("Fred", "Jones");
greet.fullName();
耐心,我的无知,是极大的赞赏。 谢谢, pychap
请仔细阅读[问]。这里没有一个适当的问题陈述,也没有一个具体的问题 – charlietfl
只需开始在* javascript工厂模式*上搜索,尝试一下,然后回来一个更加一致的例子。那么我们很乐意为您提供帮助! – pietro909