Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 将箭头函数移动到另一个导出函数_Node.js_Arrow Functions - Fatal编程技术网

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')