search

Home  >  Q&A  >  body text

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

CommonJS 规范

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

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

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

高洛峰高洛峰2902 days ago254

reply all(2)I'll reply

  • PHP中文网

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

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

    reply
    0
  • 天蓬老师

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

    this.a()
    

    reply
    0
  • Cancelreply