我试图让函数 feedAmount 打印到控制台,但我卡住了。有人可以帮我理顺吗(如果需要,可以优化它)?作为一个附加问题,我可以制作原型吗?chicken.prototype.chickenFeed("small")? 谢谢!
var chicken = new chickenObj("cluck");
chicken.talk();
function chickenObj(says) {
this.says = says;
this.talk = function talk() {
console.log("::" + this.says);
}
}
chicken.chickenFeed = new chickenFeed("small");
chicken.chickenFeed.foodAmount();
function chickenFeed(size) {
this.size = size;
function foodAmount() {
if(this.size === "small") {
this.food = "1 pound of feed";
} else if(this.size === "medium") {
this.food = "2 pound of feed";
} else if(this.size === "large") {
this.food = "3 pound of feed";
}
console.log(this.food);
}
}