在这段 javascript 中发现了哪些元素/概念?

发布于 2024-10-21 09:02:09 字数 1424 浏览 2 评论 0原文

正在闲逛,发现这对某些东西很方便,但如果你必须问我现在到底是什么,我无法告诉你,所以想知道社区是否可以帮助识别元素和概念以下...

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

Was messing around and found this to be handy for some stuff but if ya had to ask me what exactly is what right now, I wouldn't be able to tell you, so was wondering if the community could help identify elements and concepts in the following...

 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;

Usage:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

り繁华旳梦境 2024-10-28 09:02:09

由 {} 定义的 JavaScript 对象;
JavaScript 数组由 [] 定义;

将对象和数组嵌套在彼此内部;

将函数定义为对象的一部分;

JavaScript objects as defined by the {};
JavaScript arrays as defined by the [];

Nesting objects and arrays inside each other;

Defining functions as part of an object;

最单纯的乌龟 2024-10-28 09:02:09

您创建了一个名为 MyStuff 的对象(您也将其分配给 KaPow)。

它有一堆属性(STATS、difficultyLevel、Players)和一个函数(startGame)。其中一些属性本身就是对象(如统计数据和玩家)等等。例如,STATS 有自己的属性(SHOTS、SCORE、TRIES、LIVESLOST)

函数 startgame 可以对对象的属性进行操作,因为它在对象的范围内(即 this.players[0])。

You've made an object called MyStuff (which you've also assigned to KaPow).

It's got a bunch of properties (STATS, dificultyLevel, Players), and a function (startGame). Some of those properties are themselves objects (like STATS and Players) and so on and so forth. STATS, for example, has its own properties (SHOTS, SCORE, TRIES, LIVESLOST)

The function, startgame, can operate on the object's properties since it is within the scope of the object (i.e. this.players[0]).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文