1

いじり回していて、これがいくつかのことに便利であることがわかりましたが、今何が正確に何であるかを私に尋ねなければならない場合、私はあなたに話すことができないので、コミュニティが要素と概念を特定するのに役立つかどうか疑問に思っていました続く...

 var MyStuff = {

    STATS: {
            SHOTS:0,
            TRIES:0,
            HIGHESTSCORE:0,
            LIVESLOST:0
    },

    defaultLevel: 0,

    players: [
            {
                    name: 'Chuck',
                    surname: 'Norris',
                    punchline: 'Chuck Norris can set ants on fire with a magnifying glass, At night.',
                    dateCreated: '10/03/2011'
            },
            {
                    name: 'Mr',
                    surname: 'T',
                    punchline: 'I pity the fool who drinks soy milk.',
                    dateCreated: '10/03/2011'
            }
    ],

    startGame: function() {

            alert("You shouldn't have come back, " + this.players[0].surname);
            alert("" + this.players[1].punchline);
            this.STATS.SHOTS = 0;
            this.STATS.LIVESLOST = 1000000000000;
            var smiles = this.STATS.LIVESLOST;
            //TODO - More stuff
    }
}

var KaPow = MyStuff;

使用法:

    KaPow.startGame();
    alert("Starting Level: " + KaPow.defaultLevel);
    alert("Player 1: " + KaPow.players[0].name + " " + KaPow.players[0].surname);
    alert("Player 2: " + KaPow.players[1].name + " " + KaPow.players[1].surname);
    alert("Score: " + KaPow.STATS.LIVESLOST);
4

2 に答える 2

2

{} で定義された JavaScript オブジェクト。[]; で定義された JavaScript 配列。

オブジェクトと配列を互いに入れ子にする。

関数をオブジェクトの一部として定義する。

于 2011-03-10T14:11:08.657 に答える