我正在学习JavaScript,这是我试图做的,我采取了食谱,然后通过使用原型,我添加了一个方法被我定义的所有类/对象继承。我试图用原型方法打印类的属性,但它不工作
但它不工作...:C
以下是我有:
function Recipe(name, origin, auther, ingredients, directions) {
this.name = name;
this.origin = origin;
this.author = auther;
this.ingredients = ingredients;
this.directions = directions;
};
Recipe.prototype.printRecipe(){
return "<ul>" + "<li>" + this.name + "</li>" + "<li>" + this.origin + "</li>" + "<li>" + this.author + "</li>" + "<li>" + this.ingredients + "</li>" + "<li>" + this.directions + "</li>" +"</ul>";
}
var Salad = new Recipe("Fruit Salad", "Unknown", "Unknown", "Apples, Bananas, Berries, Milk, Sugar, Dry fruits", "<ul><li>sdasds</li></ul>")
document.getElementById("text").innerHTML = Salad.printRecipe();
编辑:固定,所有的代码将被格式化为代码块
OHHHH非常感谢! :d – buoyantair