I love the new Class object and the fact that I can easily extend classes and invoke the original method with $super(). It''s simply awesome! I have run into no issues with this when creating new classes as children of existing classes (for example, extending Ajax.InPlaceEditor to create a new Class), however I *do* run into issues when attempting to override existing methods (while still retaining a reference to the parent method). Please see this simple example: http://pastie.textmate.org/136199 It works for the most part. Although I would have expected the $super reference (line #24) to point to Bar''s implementation of someMethod() instead of Foo''s implementation, it is at least working to some degree. Now, if I try to override a method in Ajax.InPlaceEditor, I get entirely different behavior. Again, here is a simple example: http://pastie.textmate.org/136200 These new methods are invoked when expected (when clicking on a control that fires the in-place-editor), but I have no reference to the original method at all. Basically it seems like this code in particular is behaving like the old Class object did, where if you overrode a method you would have to duplicate all of it''s logic. My first thought was that the Class implementation for these controls (found in controls.js of scripaculous) does not use the new Prototype- style class object, but they look the same to me. Any thoughts on this? --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I suggest you subclass Ajax.InPlaceEditor like so: Ajax.CustomInPlaceEditor = Class.create(Ajax.InPlaceEditor, { /* custom methods */ }); Best, Tobie On Jan 7, 6:27 pm, mr_justin <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I love the new Class object and the fact that I can easily extend > classes and invoke the original method with $super(). It''s simply > awesome! > > I have run into no issues with this when creating new classes as > children of existing classes (for example, extending > Ajax.InPlaceEditor to create a new Class), however I *do* run into > issues when attempting to override existing methods (while still > retaining a reference to the parent method). > > Please see this simple example:http://pastie.textmate.org/136199 > > It works for the most part. Although I would have expected the $super > reference (line #24) to point to Bar''s implementation of someMethod() > instead of Foo''s implementation, it is at least working to some > degree. > > Now, if I try to override a method in Ajax.InPlaceEditor, I get > entirely different behavior. Again, here is a simple example:http://pastie.textmate.org/136200 > > These new methods are invoked when expected (when clicking on a > control that fires the in-place-editor), but I have no reference to > the original method at all. Basically it seems like this code in > particular is behaving like the old Class object did, where if you > overrode a method you would have to duplicate all of it''s logic. > > My first thought was that the Class implementation for these controls > (found in controls.js of scripaculous) does not use the new Prototype- > style class object, but they look the same to me. > > Any thoughts on this?--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
> I suggest you subclass Ajax.InPlaceEditor like so: > Ajax.CustomInPlaceEditor = Class.create(Ajax.InPlaceEditor, { > /* custom methods */ > });Yes, that is what I will likely end up doing since addMethods is not doing what I''m expecting it to. The problem with this approach is how much existing code (in JS files as well as Rails code) it will impact. Also, I am not adding new, custom methods, but simply adding new functionality to existing methods. Is this a known issue with the addMethods method or am I doing something wrong here? -justin --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
addMethods will overwrite your methods, not "inherit" them, so using $super will do what it''s doing on your example. If you just want to add features to existing functions, use Function.wrap Ajax.InPlaceEditor.prototype.someMethod Ajax.InPlaceEditor.prototype.someMethod.wrap(function() { var ret, args = $A(arguments), proceed = args.shift(); console.log("before"); ret = proceed.apply(this, args); console.log("after"); return ret; }); kangax wrote a nice article on Function.wrap: http://thinkweb2.com/projects/prototype/2007/09/14/wrap-it-up/ Best, -Nicolas On Jan 7, 2008 5:27 PM, Justin Perkins <justinperkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I suggest you subclass Ajax.InPlaceEditor like so: > > Ajax.CustomInPlaceEditor = Class.create(Ajax.InPlaceEditor, { > > /* custom methods */ > > }); > > Yes, that is what I will likely end up doing since addMethods is not > doing what I''m expecting it to. The problem with this approach is how > much existing code (in JS files as well as Rails code) it will impact. > Also, I am not adding new, custom methods, but simply adding new > functionality to existing methods. > > Is this a known issue with the addMethods method or am I doing > something wrong here? > > -justin > > > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
> addMethods will overwrite your methods, not "inherit" them, so using > $super will do what it''s doing on your example.OK, that makes sense. Thanks for clarifying. Still unsure why my simple example works well, but fails when I try to do the same with the Ajax.InPlaceEditor#createEditField method, but I guess I should move on with my life ;)> If you just want to add features to existing functions, use Function.wrapThat looks perfect, I will check it out. Thanks, justin --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 7, 2008 6:39 PM, Justin Perkins <justinperkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > addMethods will overwrite your methods, not "inherit" them, so using > > $super will do what it''s doing on your example. > > OK, that makes sense. Thanks for clarifying. Still unsure why my > simple example works well, but fails when I try to do the same with > the Ajax.InPlaceEditor#createEditField method, but I guess I should > move on with my life ;)The problem is that InPlaceEditor is a "base class" (ie, it''s not inheriting anything from anyone) so the magic for $super won''t happen during class creation :) If you subclass the IPE, as Andrew Suggests, then you''ll have "normal" access to $super as you expect :) (And it''s safer, too, since the InPlaceCollectionEditor subclasses the IPE, so any modifications to the IPE class could end up breaking the IPCE) Best, -Nicolas --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for clarifying why this is happening Nicolás. I had not thought about the impact my changes are having upon IPCE, probably because I have never used it. fyi, I am overwriting the #getText method in IPE and using function#wrap to extend #createEditField. -justin p.s. I believe you meant Tobie in your previous reply. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 7, 2008 7:54 PM, Justin Perkins <justinperkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks for clarifying why this is happening Nicolás. I had not thought > about the impact my changes are having upon IPCE, probably because I > have never used it.No problem, glad to help :)> fyi, I am overwriting the #getText method in IPE and using > function#wrap to extend #createEditField. > > -justin > > p.s. I believe you meant Tobie in your previous reply.Oops, yeah, got mixed up with the mail notifications of Andrew''s mails in other threads. Sorry Tobie :)> > > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---