I am in process of writing nodejs app. It is based on expressjs. I am confused on doing inheritance in nodejs modules. What i am trying to do is create a model base class, let\'
Using utility.inherits
can also help you decouple the child
from the parent
.
Instead of calling the parent
explicitly, you can use super_
to call the parent.
var BaseModel = require('relative/or/absolute/path/to/base_model'),
util = require('util');
function UserModel() {
this.super_.apply(this, arguments);
}
util.inherits(UserModel, BaseModel);
utility.inherits
source:
var inherits = function (ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false
}
});
};