Skip to content

Instantly share code, notes, and snippets.

@ninjabiscuit
Forked from maccman/prototypal_inheritance.js
Created September 9, 2011 17:35
Show Gist options
  • Save ninjabiscuit/1206835 to your computer and use it in GitHub Desktop.
Save ninjabiscuit/1206835 to your computer and use it in GitHub Desktop.
if (typeof Object.create !== "function")
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
var Model = {
prototype: {
init: function(){}
},
create: function(){
return Object.create(this);
},
inst: function(){
var instance = Object.create(this.prototype);
instance.init.apply(instance, arguments);
return instance;
}
};
jQuery.extend(Model, {
find: function(){},
});
jQuery.extend(Model.prototype, {
load: function(attributes){
for(var name in attributes)
this[name] = attributes[name];
}
});
var Asset = Model.create("Asset");
Asset.prototype.init = function(){
console.log('loaded')
};
var asset = Asset.inst();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment