Dopey问题。我有一个库中的对象,我想访问它,但我只是没有得到它。这是导出的对象:
exports.listAccounts = function(successCallback,errorCallback)
{
var actionDescriptor = {
method : "GET",
module : "accounts",
action : "accountlist",
useJSON: true,
};
this._run(actionDescriptor,{},successCallback,errorCallback);
};
现在我想访问etListAccounts中的代码中的帐户列表:
//user sends confirmation code and we get acesss token
app.get('/users/sendcode', function (req, res) {
console.log('verification CODE is '+req.query.vCode);
//end get verification code
et.getAccessToken(req.query.vCode,
function() {
console.log('thread entered getAccessToken function')
et.listAccounts(
function(){console.log('account list success')},
function(error) {
console.log("Error encountered while attempting " +
"to retrieve account list: " +
error);
});
// console.log(accountlist[0]);
},
function(error) {
console.log("Error encountered while attempting " +
"to exchange request token for access token: " +
error);
}
);
})
我试过这个:
et.listAccounts(
function(accountList){console.log('account list success')},
function(error) {
console.log("Error encountered while attempting " +
"to retrieve account list: " +
error);
});
我试过这个:
et.listAccounts(
function(){accountList},
function(error) {
console.log("Error encountered while attempting " +
"to retrieve account list: " +
error);
});
我试过这个:
accountList - et.listAccounts(
function(){console.log('account list success')},
function(error) {
console.log("Error encountered while attempting " +
"to retrieve account list: " +
error);
});
这是一个很好的简单问题,我觉得这很愚蠢,但是很多人都可以回答它,很多初学者会发现它很有用。
答案 0 :(得分:0)
在您与我们分享的代码段中,您似乎没有导入该模块。请阅读此处的文档:
https://nodejs.org/docs/latest/api/modules.html#modules_accessing_the_main_module
var imported = require('nameOfModule');