0
このコードは自分の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"
})
あなたはポケモンオブジェクトを作成するために渡されたパラメータ{...}は一つのオブジェクトではなく、5つのデータです。これは、5つのパラメータではなく、1つのパラメータ - 「名前」として認識されます。残りのパラメータtype1、type2、height、weightは未定義です。 – Kelvin
http://tinypic.com/r/sl4rj9/9 ここではこれが私の問題です。特定の情報は得られません。 haha – JHillman
あなたは何をするつもりなのかわからない – Kelvin