Categories
Uncategorized

JavaScript inheritance

ECMAScript doesn’t have an inherit function. But you can mimic the functionality yourself if you need to.

Here’s a ready made inherit function you can use in your project:

// namespace var lib = {}; // cloneObject function // For browsers that have Object.create if(Object.create) { lib.cloneObject = function(o) { return Object.create(o); }; } else { lib.cloneObject = (function() { var Fn = function() {}; return function(o) { Fn.prototype = o; return new Fn(); }; })(); } // innherit function lib.inherit = function(Sub, Super) { // Clone parent’s prototype to child’s prototype Sub.prototype = lib.cloneObject(Super.prototype); // Assign super constructor to

See original post