搜索

首页  >  问答  >  正文

javascript - 在 CommonJS 规范中,如何优雅地引用本模块暴露出去的变量或者函数?

CommonJS 规范

现在的写法是前面写 module.exports,比如:

module.exports = {
  a: function(){ console.log('Hi'); },
  b: module.exports.a()
}

但这样有写感觉略长,不太优雅的感觉,不知道有没有比较优雅的写法?

高洛峰高洛峰2903 天前256

全部回复(2)我来回复

  • PHP中文网

    PHP中文网2017-04-10 15:12:59

    var a = function(){ console.log('Hi'); };
    
    module.exports = {
      a: a,
      b: a
    }
    

    回复
    0
  • 天蓬老师

    天蓬老师2017-04-10 15:12:59

    this.a()
    

    回复
    0
  • 取消回复