Extending prototype classes in node.js or javascript in general. (js newb)
I looked at the source code of expressjs and saw this :
var mixin = require('utils-merge');
....
mixin(app, proto);
mixin(app, EventEmitter.prototype);
Utils-mergeLooks like an external module. What is the difference above and just something like:
var util = require('util');
....
util.inherit(app, proto);
util.inherit(app, EventEmitter);
And still trying to expand properties? I am kind, lost here:
app.request = { __proto__: req, app: app }; // what is the equivalent for this in util?
app.response = { __proto__: res, app: app };
If so, will it work, even if used util.inherit?
app.request = util.inherit(app, req)
Or something like that? jshint says it's __proto__stripped.
Also, have I also seen this?
var res = module.exports = {
__proto__: http.ServerResponse.prototype
};
Could it be?
var res = module.exports = util.inherits...??
source
share