模块化模式vs原型 – Nodejs?

我在Nodejs工作。 我曾经在modular pattern 。 编码简单易行。

注意

我的同事告诉Prototype模式是Nodejs和Modular模式最好的方法。

我的代码示例

 module.exports = { get : funcntion(){ //stuff }, set : function(){ //stuff } } 

什么样的模式对于实时Web应用程序来说是最好的,或者一般情况下是使用Nodejs的应用程序上下

让我把这个想法放在这里:

 // vinoth.js var Vinoth = function () {}; Vinoth.prototype.log = function () { console.log('Hello Vinoth'); }; module.exports = new Vinoth(); // app.js var vinoth = require('./vinoth.js'); vinoth.log(); 

简单的module模式

 //vinoth.js module.exports = function () { console.log('Vinoth'); } // app.js var vinoth = require('./vinoth.js'); vinoth(); 

从我所understand是:

Prorotype pattern可以帮助您inheritance和扩展function,并且不pipe对象的数量如何,内存中只有一个函数实例。 Vinoth.prototype.log添加到prototype并且不会为新对象再次创build此函数。

Modular pattern ,为每个对象创build一个新的函数实例,但可以帮助您进行encapsulation