Javascript构造函数没有';行不通
我有一些数组和一个简单的构造函数,但不知怎么的,我就是不能让它工作Javascript构造函数没有';行不通,javascript,arrays,constructor,Javascript,Arrays,Constructor,我有一些数组和一个简单的构造函数,但不知怎么的,我就是不能让它工作 var suit = ["ruutu", "risti", "\u00E4rtu", "poti"], type = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "soldat", "emand", "kuningas", "\u00E4ss"], pnt = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11], ca
var suit = ["ruutu", "risti", "\u00E4rtu", "poti"],
type = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "soldat", "emand", "kuningas", "\u00E4ss"],
pnt = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11],
card = {}, // 3 properties: suit, type, pnt)
Cards = [];
Cards = makeDeck(card, suit, type, pnt, Cards);
card = new NewCard(Cards);
function makeDeck(card, suit, type, pnt, Cards) {
"use strict";
var i,
j;
for (i = 0; i < 4; i = i + 1) {
for (j = 0; j < 13; j = j + 1) {
card = {
suit : suit[i],
type : type[j],
pnt : pnt[j]
};
Cards.push(card);
}
}
return Cards;
}
function NewCard(Cards) {
"use strict";
var i = Math.floor(Math.random() * 52);
this.suit = Cards[i].suit;
this.type = Cards[i].type;
this.pnt = Cards[i].pnt;
}
var suit=[“ruutu”,“risti”,“\u00E4rtu”,“poti”],
类型=[“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”、“10”、“soldat”、“emand”、“kuningas”、“u00E4ss”],
pnt=[2,3,4,5,6,7,8,9,10,10,10,10,11],
card={},//3个属性:suit、type、pnt)
卡片=[];
卡片=makeDeck(卡片、套装、类型、pnt、卡片);
卡片=新卡(卡);
功能makeDeck(卡片、套装、类型、pnt、卡片){
“严格使用”;
var i,
J
对于(i=0;i<4;i=i+1){
对于(j=0;j<13;j=j+1){
卡片={
西服:西服,,
类型:类型[j],
pnt:pnt[j]
};
卡片。推(卡片);
}
}
回程卡;
}
功能新卡(卡){
“严格使用”;
var i=Math.floor(Math.random()*52);
this.suit=Cards[i].suit;
this.type=Cards[i].type;
this.pnt=Cards[i].pnt;
}
我可以在Firebug中看到,虽然this.suit和this.type得到了它们的值,但是this.pnt仍然没有定义。为什么?它是否与数据类型(数字与字符串)有关
提前谢谢 你的代码对我有用。如果我发出
警报(this.pnt)
紧接着this.pnt=Cards[i].pnt代码>警报显示一个数字。到底是什么问题?相同。运行此提琴时,请查看控制台:问题可能是我是一个过度疲劳的javascript初学者。:)它现在适合我了。抱歉给您带来了困惑,再次感谢您!