0

Hi I am learning the source code about morgan

when I saw the line morgan.format('combined', ...) for my understand, why it can run success and not cause morgan.format is not a function. when I extract the main code run in my local and I got the error. how this place is implemented?

can anybody tell me ? thanks in advance.

4

1 回答 1

0

感谢主函数可以访问module.exports该方法的魔法。format()morgan()

这是一个最小的复制:

module.exports = morgan
module.exports.format = format  // format() method is now available to morgan

function morgan() {}

morgan.format()  // Hello from format()

function format() {
  console.log('Hello from format()')
}

简而言之,module.exports.some_method = some_methodsome_method()功能添加到主模块中。

于 2018-01-31T18:14:52.150 回答