简体   繁体   English

Javascript / Node.js“函数名称”不是函数

[英]Javascript/Node.js “Function name” is not a function

So I have this function which was working fine yesterday but today when I turned PC on it stopped working. 因此,我有此功能,该功能昨天工作正常,但今天当我打开PC时,它停止工作。 Were there any updates that I am not aware of, did i maybe accidentally delete something, but I haven't touched code since yesterday? 是否有我不知道的任何更新?我是否可能不小心删除了某些内容,但是自昨天以来我从未接触过代码? Can someone help me find this annoying bug? 有人可以帮我找到这个烦人的错误吗?

Function I'm trying to reach is inside other folder and other script. 我要访问的功能在其他文件夹和其他脚本中。

Here is the function: 这是函数:

var npcSchema = new mongoose.Schema({
    NPCname: {type: String, unique:true},
    life: Number,
    zone : String,
    pos_x: Number,
    pos_y: Number,
    zgodba: Boolean
});

npcSchema.NarediNpc = function(imeNpc, socket){
    NPC.findOne({NPCname: imeNpc}, function(err, npc){
        socket.write(packet.build([
            "NPC",
            npc.NPCname,
            npc.life,
            npc.zone,
            npc.pos_x,
            npc.pos_y
        ]));
    })
};

module.exports = NPC = gamedb.model('npcs', npcSchema);

And this is the code where I'm trying to access the function: 这是我尝试访问该函数的代码:

var npcNaredi = new require('./Models/user.js');
case "NPC":              
    npcNaredi.NarediNpc("obj_npcLograk", c.socket);
    break;

Variables and function names are written in slovene, I hope that won't make problems, it might actually be just some stupid typo but I can't find it and I'm getting headache from this... 变量和函数名用slovene编写,我希望不会出现问题,它实际上可能只是一些愚蠢的错字,但我找不到它,对此我感到头痛。

I see that you are trying to create an instance method, try this: 我看到您正在尝试创建实例方法,请尝试以下操作:

npcSchema.methods.NarediNpc = function(imeNpc, socket){
  // ...
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM