Skip to content

Instantly share code, notes, and snippets.

@jpillora
Last active December 15, 2015 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpillora/5342557 to your computer and use it in GitHub Desktop.
Save jpillora/5342557 to your computer and use it in GitHub Desktop.
JavaScript Prototypical Object Inheritance
//Object create with object extension
function inherit(parent, object) {
function F(){}
F.prototype = parent
return $.extend(new F(), object);
}
//Crockford's Object.create polyfill
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment