2016-08-19 82 views
0

我有以下代碼:在node.js中編程調用函數

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)); 
} 

而且我不知道如何調用它的代碼的其他部分。

我已經試過這樣:

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

,但沒有奏效。 我想不使用setTimeout函數。

+0

如何創建'exchange'變量? – vfabre

+1

您的'checkOrder'方法的代碼不完整,請添加完整代碼 – Maxx

+0

在節點中,您可以使用module.exports在其他部分獲取此數據。 –

回答

0

由於您使用的是原型,您可能首先需要創建一個對象。之後,您可以像調用其他函數一樣調用該方法。

+0

我可以直接使用this.checkOrder()嗎? – Saeeds255

+0

不是因爲你在你的方法中有副作用(this.action)需要綁定到一個對象 –