0

我有一些数组和一个简单的构造函数,但不知何故我无法让它工作。

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;
}

我可以在 Firebug 中看到,虽然 this.suit 和 this.type 获得了它们的值,但 this.pnt 仍未定义。为什么?它与数据类型(数字与字符串)有关吗?

提前致谢!

4

0 回答 0