I have declared a class in a traditional way, that is,
function myClass ( } {} MyClass.prototype = {}; Now I want to copy that class (for example, class creates a copy), but change some prototype methods. In other words, I want to copy some enhanced class ... do I need to use heritage for this or am I enough to loop and specify the context for my new class for the original prototype and the new one?
I will use general inheritance to try it:
var MyClass = Function () {}; MyClass.prototype = {foo: function () {warning ('foo')}, bar: function () {alert ('bar')}}; Var MySubClass = function () {}; MySubClass.prototype = New MyClass (); MySubClass.prototype.bar = Function () {Warning ('Other')}; Var My = new MyClass (); Var mysub = New MySubClass (); My.foo (); // foo my.bar (); // times mysub.foo (); // foo mysub.bar (); // Other Bar
Comments
Post a Comment