1

javascriptでこの(機能していない)コードに「似た」何かを実行できることを知りたいですか?

function Player ()     {

    this.Inventory = function ()     {

        this.Inventory.UseItem = function(item_id)    {
            /* use the item ... */
        }

    }

}

そしてそれをそのように使用します:

current_player = new Player();
current_player.Inventory.UseItem(4);
4

3 に答える 3

3
function Player() {
    this.Inventory = {
        UseItem: function(item_id) {
            // code here
        }
    };
}

それを試してみてください。

于 2012-04-07T01:27:27.613 に答える
0
current_player = new Player();
current_player.prototype.Inventory = {
         UseItem : function(item_id)    {
            /* use the item ... */
        }
}
于 2012-04-07T01:26:47.177 に答える
-1

うん

function Player ()     {

    var Inventory = {


        UseItem : function(item_id)    {
            /* use the item ... */
        }

    };

}
于 2012-04-07T01:31:54.267 に答える