【发布时间】:2016-05-23 22:09:59
【问题描述】:
所以这段代码是用于我的 javascript 类的,所以它对于网站本身来说并不是必不可少的,但我仍然被困住了。所以我正在尝试编写一个代码,当我调用某个名称和方法(名称、类型 1、类型 2、身高或体重)时,我会得到我在代码中提供的答案。我越来越不确定,但是在查看我的讲师的演示时,它可以工作。
我希望我没有错过一些非常简单的东西。非常感谢任何帮助!
var Pokemon = function Pokemon(name , type1 , type2 , height , weight) {
this.name = name;
this.type1 = type1;
this.type2 = type2;
this.height = height;
this.weight = weight;
}
Pokemon.prototype.whichPoke = function whichPoke() {
console.log("Hey, I am " + this.name);
}
Pokemon.prototype.whichType1 = function whichType1() {
console.log("Hey, I am " + this.type1);
}
Pokemon.prototype.whichType2 = function whichType2() {
console.log ("Hey, I am " + this.type2);
}
Pokemon.prototype.whichHeight = function whichHeight() {
console.log ("Hey, I am " + this.height + " inches tall");
}
Pokemon.prototype.whichWeight = function whichWeight() {
console.log ("Hey, I am " + this.weight + " pounds")
}
var Horsea = new Pokemon({
name: "Horsea",
type1: "Water",
type2: "none",
height: "16",
weight: "17.6"
})
var Seadra = new Pokemon({
name: "Seadra",
type1: "Water",
type2: "none",
height: "47",
weight: "55.1"
})
var Kingdra = new Pokemon({
name: "Kingdra",
type1: "Water",
type2: "Dragon",
Height: "71",
Weight: "335.1"
})
【问题讨论】:
标签: javascript function methods console prototype