I'm not sure where you got the code from for that extend
function but it's horribly incorrect.
I've formatted it a bit better so we can see the issues:
var Base = function(db) {
this.db = db;
};
Base.prototype = {
extend: function(properties) {
var Child = Base; // what?
Child.prototype = Base.prototype; // what?
for(var key in properties) {
Child.prototype[key] = properties[key];
}
return Child;
}
};
In your extend function:
You're setting the child object to be a reference to the super object, thus you're effectively changing the super object, thus all other objects that rely on the super prototype will be affected.
This is probably what you want to do:
var Base = function(db) {
this.db = db;
};
Base.prototype = {
extend: function(properties) {
var Child = function(){
Base.apply(this, arguments);
};
Child.prototype = Object.create(Base.prototype);
for(var key in properties) {
Child.prototype[key] = properties[key];
}
return Child;
}
};
For inheritance in node.js, personally I would just stick with util.inherits
. Have a read on Object.create to view more inheritance examples.