docs:programming:javascript:copy_prototype

copy prototype

This is a function to allow basic inheritance. You can have a parent class, and a descendant class which inherits all prototype components of the parent class.

function copyPrototype(descendant, parent) {
    var sConstructor = parent.toString();
    var aMatch = sConstructor.match( /\s*function (.*)\(/ );
    if ( aMatch != null ) { descendant.prototype[aMatch[1]] = parent; }
    for (var m in parent.prototype) {
        descendant.prototype[m] = parent.prototype[m];
    }
};
  • docs/programming/javascript/copy_prototype.txt
  • Last modified: 2008/08/03 00:25
  • by 127.0.0.1