Node.js - use of module.exports as a constructor

后端 未结 5 1925
孤城傲影
孤城傲影 2020-11-30 16:41

According to the Node.js manual:

If you want the root of your module\'s export to be a function (such as a constructor) or if you want to export a c

5条回答
  •  一整个雨季
    2020-11-30 17:27

    At the end, Node is about Javascript. JS has several way to accomplished something, is the same thing to get an "constructor", the important thing is to return a function.

    This way actually you are creating a new function, as we created using JS on Web Browser environment for example.

    Personally i prefer the prototype approach, as Sukima suggested on this post: Node.js - use of module.exports as a constructor

提交回复
热议问题