Last active
December 15, 2015 23:48
-
-
Save jpillora/5342557 to your computer and use it in GitHub Desktop.
JavaScript Prototypical Object Inheritance
This file contains hidden or 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
//Object create with object extension | |
function inherit(parent, object) { | |
function F(){} | |
F.prototype = parent | |
return $.extend(new F(), object); | |
} |
This file contains hidden or 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
//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