javascript - Extending, instead of overwriting, the prototype -
in our current codebase, creating classes this
my_class = function(){ //do constructor stuff } my_class.prototype = { var1 : 'value', var2 : 'value', var3 : 'value' . . . //etc }
there several classes like inherit super class. however, if this, end overwriting superclass' prototype.
my_super_class = function(){ } my_super_class.prototype.generic_function = function(){ //all subclasses should have function } my_subclass = function(){ //constructory stuff } //inherit superclass my_class.prototype = new my_super_class(); my_class.prototype = { //oops, there goes superclass prototype... var1 : 'value', var2 : 'value', var3 : 'value' . . . //etc }
is there better way my_class.prototype.val1 = 'value'; ... etc after inheriting superclass? follow convention our current codebase because short , point.
do use library or framework? if chances can use prototype's object.extend or jquery.extend.
what might find interesting new object.create ecma-262 5th edition.
Comments
Post a Comment