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.
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
Post a Comment