Created
April 4, 2014 07:12
-
-
Save badsyntax/9969627 to your computer and use it in GitHub Desktop.
Broken extends in the browser, stick this in your console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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