Node.js 将箭头函数移动到另一个导出函数
我有个问题。我想清理代码并将函数放到另一个文件中,但总是出现错误:Node.js 将箭头函数移动到另一个导出函数,node.js,arrow-functions,Node.js,Arrow Functions,我有个问题。我想清理代码并将函数放到另一个文件中,但总是出现错误: getMe is not a function 为什么??我想在已经导出的函数GetExchangeIntent中使用它。这会引起问题吗 outside.js const getRate = (base) => { console.log('My base currency is '+base); }; module.exports = {getRate}; const getMe = ('./outside.j
getMe is not a function
为什么??我想在已经导出的函数GetExchangeIntent中使用它。这会引起问题吗
outside.js
const getRate = (base) => {
console.log('My base currency is '+base);
};
module.exports = {getRate};
const getMe = ('./outside.js');
module.exports = {
'getExchangeRateIntent': (conv, parameter) => {
const currencyBase = (parameter['currencyBase']);
const currencyTarget = (parameter['currencyTarget']);
const amount = (parameter['amount']);
console.log(currencyBase);
console.log(currencyTarget);
console.log(amount);
getMe('USD');
conv.ask('nothing');
},
getRate.js
const getRate = (base) => {
console.log('My base currency is '+base);
};
module.exports = {getRate};
const getMe = ('./outside.js');
module.exports = {
'getExchangeRateIntent': (conv, parameter) => {
const currencyBase = (parameter['currencyBase']);
const currencyTarget = (parameter['currencyTarget']);
const amount = (parameter['amount']);
console.log(currencyBase);
console.log(currencyTarget);
console.log(amount);
getMe('USD');
conv.ask('nothing');
},
})
module.exports={getRate}代码>您正在导出对象。在导入时:
constgetme=('./outside.js')代码>
您正在导入一个对象。所以这不是一个函数。这也不是一个适当的进口
要正确导入,您可以编写如下内容:
import{getRate}from./outside.js
然后像这样使用它:
getRate('USD')代码>
或者,如果要使用,则需要:
const getMe=require('./outside.js')代码>
在第二种情况下,您可以调用如下函数:
getMe.getRate('USD')