我正在尝试使用需求的基本原型,我在网上查看了示例,但它们似乎不起作用(Node 4.0.0)。
我来自JAVA背景,我正在尝试为Javascript制作对象和静态方法(我知道JavaScript不是OOP,但你可以让它'看起来像'OOP)
//Player.js
var Player = function(name)
{
this.name = name;
}
//Map<name,Player>
Player.prototype.playersOnline = [];
Player.prototype.getPlayerFromName = function(name)
{
if(Player.playersOnline[name] != undefined)
{
return Player.playersOnline[name];
}
return undefined;
};
module.exports = Player;
问题
//Main app.js
var Player = require('./objects/Player');
Player.getPlayerFromName(name) << TypeError: undefined is not a function