Skip to content

Instantly share code, notes, and snippets.

@badsyntax
Created April 4, 2014 07:12
Show Gist options
  • Save badsyntax/9969627 to your computer and use it in GitHub Desktop.
Save badsyntax/9969627 to your computer and use it in GitHub Desktop.
Broken extends in the browser, stick this in your console.
var Model = function(db) {
this.db = db;
}
Model.prototype.extend = function(properties) {
var Child = Model;
Child.prototype = Model.prototype;
for(var key in properties) {
Child.prototype[key] = properties[key];
}
return Child;
};
var model = new Model();
var BlogModel = model.extend({
results: 10,
getContent: function() {
return "blog content, results: " + this.results;
}
});
var blogModel = new BlogModel();
var ContactsModel = model.extend({
results: 50,
getContent: function() {
return "contacts content, results: " + this.results;
}
});
var contactsModel = new ContactsModel();
console.log(blogModel.getContent()); // contacts content, results: 50
console.log(contactsModel.getContent()); // contacts content, results: 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment