Hi Is there a way to extend a class and to overide a method and, in this method, to call the parent function as it is done in mootools? Thanks Seb --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
mySuperClass = Class.create(); mySuperClass.prototype { initialize: function(id) { this.id = id; }, doSomething: function() { alert(this.id + " base doSomething()"); } }; mySubClass = Class.create(); mySubClass.prototype { initialize: function(id) { //cache the base class instance this.base = new mySuperClass(id); //inherit from the base class Object.extend(this, this.base); //override methods this.doSomething = function() { alert(this.id + " overridden doSomething()"); this.base.doSomething(); }; } }; On 9/12/06, Sébastien Gruhier <sgruhier-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hi > > Is there a way to extend a class and to overide a method and, in this > method, to call the parent function as it is done in mootools? > Thanks > Seb > > > > >-- Ryan Gahl Application Development Consultant Athena Group, Inc. Inquire: 1-888-919-8700 x2903 Blog: http://www.someElement.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
> Is there a way to extend a class and to overide a method and, in this > method, to call the parent function as it is done in mootools? > ThanksWell, a hackish way is to do this: newClass.prototype.oldMethod = oldClass.prototype.method; newClass.prototype.method = function (args) { this.oldMethod(args); // do some other stuff }; Replace the word ''method'' with your method name, etc, etc. There''s probably a better way, but that''s how I''ve done it in a hurry before. Greg --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
On 9/12/06, Sébastien Gruhier <sgruhier-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi > > Is there a way to extend a class and to overide a method and, in this > method, to call the parent function as it is done in mootools? > Thanks > SebIn Prototype.js, pseudo-inheritance is implemented by copying properties of one class to another. This isn''t really inheritance like you are thinking and there is no chain of classes for method lookup when a call like foo.bar() is made. If you want class-based inheritance like Ruby or Java then have a look at this tutorial. http://kevlindev.com/tutorials/javascript/inheritance/index.htm This is the single best JavaScript tutorial I have read. Yahoo! uses this technique in their JavaScript library. Peter --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Thanks to all of you guys, I hope it will be in prototype 2.0. Greg , you had the same idea than me (same hurrt I guess) Seb Le 12 sept. 06 à 18:04, Peter Michaux a écrit :> > On 9/12/06, Sébastien Gruhier <sgruhier-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> Hi >> >> Is there a way to extend a class and to overide a method and, in this >> method, to call the parent function as it is done in mootools? >> Thanks >> Seb > > In Prototype.js, pseudo-inheritance is implemented by copying > properties of one class to another. This isn''t really inheritance like > you are thinking and there is no chain of classes for method lookup > when a call like foo.bar() is made. > > If you want class-based inheritance like Ruby or Java then have a look > at this tutorial. > > http://kevlindev.com/tutorials/javascript/inheritance/index.htm > > This is the single best JavaScript tutorial I have read. Yahoo! uses > this technique in their JavaScript library. > > Peter > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---