Created
January 14, 2015 22:53
-
-
Save WebReflection/6a04e06bba72465cebab to your computer and use it in GitHub Desktop.
good old prototypal inheritance done without leaks
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 inherit = (function () { | |
function Constructor() { | |
// always reassign the initial | |
// prototype to avoid problems | |
// in jurassic engines | |
Constructor.prototype = cp; | |
} | |
// original prototype | |
var cp = Constructor.prototype; | |
// the inherit function | |
return function (object) { | |
// assign it once | |
Constructor.prototype = object; | |
// and drop any reference once constructoed | |
return new Constructor; | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if you need classes like inheritance that works down to IE6 or lower but it's compatible with modern and future standards have a look at es-class