node.js - Difference between initating an express object in nodejs? -


i can use express in 2 ways, can initialize in 2 ways:

var app = express(); or var app = new express();

from looks of things, both calling constructor, there difference between two, i'm asking performance wise, there difference, because seemed have experienced none.

if there no real difference how come every tutorial i've seen first way , not second way, because second 1 seems clearer.

in case calling express() function more correct.

https://github.com/visionmedia/express/blob/8a1e865e37016f279d957f04117007c36ac195e3/lib/express.js#l32

function createapplication() {   var app = connect();   utils.merge(app, proto);   app.request = { __proto__: req, app: app };   app.response = { __proto__: res, app: app };   app.init();   return app; } 

this factory function, not constructor. using new keyword create unnecessary object discarded since createapplication returns object, automatic this new keyword creates discarded (this how javascript language works).

so answer both versions work fine, using new unnecessary here.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -