我正在學習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