Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created January 14, 2015 22:53
Show Gist options
  • Save WebReflection/6a04e06bba72465cebab to your computer and use it in GitHub Desktop.
Save WebReflection/6a04e06bba72465cebab to your computer and use it in GitHub Desktop.
good old prototypal inheritance done without leaks
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;
};
}());
@WebReflection
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment