简体   繁体   English

在node.js编程中调用函数

[英]Call a function in node.js programming

I have the following code: 我有以下代码:

Manager.prototype.checkOrder = function() {
    var finish = function(err, filled) {
        if(!filled) {
            log.info(this.action, 'order was not (fully) filled, cancelling and creating new order');
            this.exchange.cancelOrder(this.order);
        }
        log.info(this.action, 'was successfull');
    }
    this.exchange.checkOrder(this.order, _.bind(finish, this));
}

And I don't know how to call it on other parts of the code. 而且我不知道如何在代码的其他部分调用它。

I have tried this : 我已经试过了:

setTimeout(this.checkOrder, util.minToMs(1));

but it didn't work. 但这没用。 I want to do it without using setTimeout function. 我想在不使用setTimeout函数的情况下进行操作。

As you are using prototypes you probably want to create an Object first. 在使用原型时,您可能首先要创建一个对象。 After that you can call the method like every other function. 之后,您可以像调用其他所有函数一样调用该方法。

var myManager = new Manager();
myManager.checkOrder();

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

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