2015-10-13 47 views
0

我正在嘗試使用highlandheroku-client結合使用。但在Heroku客戶端的內部,它使用this,即使我嘗試bind來綁定這個,函數給出了錯誤消息,並且有一個對於this的錯誤消息,我無法使其工作。結合使用高地與節點客戶端

沒有權代碼看起來像這樣

const Heroku = require('heroku-client'); 
const hl = require('highland'); 
var hk = new Heroku({ 
    token: process.env.HEROKU_API_TOKEN 
}); 
var list = hl.wrapCallback(hk.apps().list.bind(hk)); 
list().toArray((a) => 'console.log(a)') 

所以這個代碼片斷失敗,出現以下錯誤信息:

...node_modules/heroku-client/lib/resourceBuilder.js:35 
if (this.params.length !== pathParams.length) { 
      ^

TypeError: Cannot read property 'length' of undefined 

回答

1

呦! :-)

你結合hk,而不是什麼hk.apps()回報,這是什麼list功能依賴於(這是什麼hk.apps()回報的成員)

試試這個:

const Heroku = require('heroku-client'); 
const hl = require('highland'); 
const hk = new Heroku({ 
    token: process.env.HEROKU_API_TOKEN 
}); 
const hkApps = hk.apps(); 
const list = hl.wrapCallback(hkApps.list.bind(hkApps)); 
list().toArray((a) => 'console.log(a)') 
+0

這作品。唯一要提到的是從我的問題中複製粘貼,我在這裏執行'(a)=>'console.log(a)''而不是'(a)=> console.log(a)'。 –