Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/models/Base.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
var util = require('util');
module.exports = function(db) {
this.db = db;
};
module.exports.prototype = {
extend: function(properties) {
var Child = module.exports;
Child.prototype = module.exports.prototype;
var Child = function(db) {
this.db = db;
};
util.inherits(Child, module.exports);
for(var key in properties) {
Child.prototype[key] = properties[key];
}
Expand Down
17 changes: 16 additions & 1 deletion app/tests/base.model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,22 @@ describe("Models", function() {
});
var model2 = new OtherTypeOfModel(dbMockup);
expect(model2.db).toBeDefined();
expect(model2.setDB).toBeDefined();
expect(model2.myCustomModelMethod).toBeDefined();
next();
})
});
it("should not modify the base prototype chain", function(next) {
var model = new Model(dbMockup);
var A = model.extend({
prop: 20
});
var B = model.extend({
prop: 30
});
var a = new A();
var b = new B();
expect(a.prop).toBe(20);
expect(b.prop).toBe(30);
next();
});
});
14 changes: 14 additions & 0 deletions app/tests/base.view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,18 @@ describe("Base view", function() {
expect(otherViewInstance.render).toBeDefined();
otherViewInstance.render({prop: 'yes'});
});
it("should not modify the base prototype chain", function(next) {
var v = new View();
var A = v.extend({
prop: 20
});
var B = v.extend({
prop: 30
});
var a = new A();
var b = new B();
expect(a.prop).toBe(20);
expect(b.prop).toBe(30);
next();
});
});
8 changes: 6 additions & 2 deletions app/views/Base.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
var util = require('util');
module.exports = function(response, template) {
this.response = response;
this.template = template;
};
module.exports.prototype = {
extend: function(properties) {
var Child = module.exports;
Child.prototype = module.exports.prototype;
var Child = function(response, template) {
this.response = response;
this.template = template;
};
util.inherits(Child, module.exports);
for(var key in properties) {
Child.prototype[key] = properties[key];
}
Expand Down