Javascript 如何设置回调和传递node.js模块函数变量
我试图将customerId、customerDescription和customerEmail传递到createCustomerProfile中,该文件是从单独的模块导入的 回调变量是原始作者的默认值,我正在尝试扩展模块以获取这些额外的变量 我能把它们传进来吗?我尝试使用bind函数,但它不断抛出错误,我不知道如何继续。我以前也遇到过类似的问题,使用对象文字语法来传递类似JSON的数据,但回调变量让我感到厌烦 index.jsJavascript 如何设置回调和传递node.js模块函数变量,javascript,node.js,function,Javascript,Node.js,Function,我试图将customerId、customerDescription和customerEmail传递到createCustomerProfile中,该文件是从单独的模块导入的 回调变量是原始作者的默认值,我正在尝试扩展模块以获取这些额外的变量 我能把它们传进来吗?我尝试使用bind函数,但它不断抛出错误,我不知道如何继续。我以前也遇到过类似的问题,使用对象文字语法来传递类似JSON的数据,但回调变量让我感到厌烦 index.js const profiles = require('./autho
const profiles = require('./authorize-net/lib/init-profile.js');
profiles.createCustomerProfile(function() {
console.log('call back');
});
init-profile.js
// require some stuff...
function createCustomerProfile(callback, customerId, customerDescription, customerEmail) {
let cardNumber = '4242424242424242';
let cardExp = '0822';
// set some properties...
let customerProfileType = new ApiContracts.CustomerProfileType();
customerProfileType.setMerchantCustomerId(customerId);
customerProfileType.setDescription(customerDescription);
customerProfileType.setEmail(customerEmail);
customerProfileType.setPaymentProfiles(paymentProfilesList);
let ctrl = new ApiControllers.CreateCustomerProfileController(createRequest.getJSON());
ctrl.execute(function(){
let apiResponse = ctrl.getResponse();
let response = new ApiContracts.CreateCustomerProfileResponse(apiResponse);
callback(response);
});
}
if (require.main === module) {
createCustomerProfile(function(){
console.log('createCustomerProfile call complete.');
});
}
module.exports.createCustomerProfile = createCustomerProfile;
回调在参数列表中排在最后。是作为回调传入的
index.js
中的嵌套函数吗?我应该使用bind
?