Javascript 在另一个键函数中的对象中引用函数

Javascript 在另一个键函数中的对象中引用函数,javascript,node.js,function,object,Javascript,Node.js,Function,Object,我有一个模块导出如下,我想调用另一个函数,在这种情况下可能吗 module.exports = { first:() => { // this is my first function }, second:() => { // I want to call my first function here // I have tried this this.first() } } 您可以像这样从其他模块访问它 const {first

我有一个模块导出如下,我想调用另一个函数,在这种情况下可能吗

module.exports = {
  first:() => {
    // this is my first function
  },
  second:() => {
    // I want to call my first function here
    // I have tried this 
    this.first()

  }
}

您可以像这样从其他模块访问它

const {first, second } = require('./module2');
first();
second();


您可以定义
模块。首先在变量中导出
,然后在
第二个
中使用它,如下所示:

第一个文件(other.js):

const _this = (module.exports = {
  first: () => {
    console.log("first");
  },
  second: () => {
    _this.first();
  }
});
import other from "./other";

other.second();
first
第二个文件(index.js):

const _this = (module.exports = {
  first: () => {
    console.log("first");
  },
  second: () => {
    _this.first();
  }
});
import other from "./other";

other.second();
first
输出:

const _this = (module.exports = {
  first: () => {
    console.log("first");
  },
  second: () => {
    _this.first();
  }
});
import other from "./other";

other.second();
first

你可以在导出之前定义函数,然后按照你的意愿重用它们。好吧,我知道这种方法,但我认为可能还有另一种方法,因为它不只是使用普通函数而不是箭头函数来解决问题吗?我使用了function关键字,但它没有解决它@strahinjai不要给我这个错误。first不是函数@strahinja