javascript - How to inherit Express router and also call super inside method? -
express router function want "inherit"/extend
var proto = module.exports = function(options) { var opts = options || {}; function router(req, res, next) { router.handle(req, res, next); } // mixin router class functions router.__proto__ = proto; router.params = {}; router._params = []; router.casesensitive = opts.casesensitive; router.mergeparams = opts.mergeparams; router.strict = opts.strict; router.stack = []; return router; };
so purpose create own function/class extend express router , override route
method accept parameter being able call super.route
of express router
i've tried several ways, including util.inherits
nothing worked.
if possible please provide explanations also
end goal this:
var testrouter = express.router(); testrouter.route('/test-route', 'aaa' /* param here */) .get(controller.testwhatever)
being able override route method add new parameter preserve old functionality.
think example explains looking for
// create class function vehicle(color){ this.color = color; } // add instance method vehicle.prototype.go = function(){ return "underway in " + this.color; } // add second class function car(color){ this.color = color; } // , declare subclass of first car.prototype = new vehicle(); // override instance method car.prototype.go = function(){ return vehicle.prototype.go.call(this) + " car" } // create instances , see overridden behavior. var v = new vehicle("blue"); v.go() // "underway in blue" var c = new car("red"); c.go() // "underway in red car"
Comments
Post a Comment