JavaScript / node - 作为参数的函数数组

时间:2016-03-26 14:36:18

标签: javascript arrays function parameters arguments

我通过这样的其他问题看了看,我想我正在做答案所说的。我仍然得到一个节点TypeError,其中包含以下内容:

const ALL_ITEM_CLASSES = [
    require( './equipment/torsoe/LightTorsoe.js' ),
    require( './equipment/torsoe/MedTorsoe.js' ),
    require( './equipment/torsoe/HeavyTorsoe.js' ),
    require( './equipment/boots/LightBoots.js' ),
    require( './equipment/boots/MedBoots.js' ),
    require( './equipment/boots/HeavyBoots.js' )
];

var ItemGenerator = {
    getRandomItem: function( classArray, minQuality, maxQuality ) {
        if( !classArray ) {
            classArray = ALL_ITEM_CLASSES;
        }

        var ItemClass = classArray[ Math.floor(Math.random()*classArray.length) ]; 

        return ItemClass( minQuality + Math.random()*(maxQuality-minQuality) ); // TypeError: ItemClass is not a function
    }
}

用法:

var boots = ItemGenerator.getRandomItem( [LightBoots,MedBoots,HeavyBoots], 0, 1.0 )

有人告诉我我做错了什么吗?感谢...

P.S。根据@Pointy的评论,这里是其中一个类的例子(其余的都是相同的样板):

var LightBoots = function( quality ) {
    return {
        slot: "boots",
        type: "light",
        quality: quality,
        armorClass: Math.round( 2+quality*3.5 ),
        magicalGravity: quality
    };
}
module.exports = LightBoots;

0 个答案:

没有答案