I might get in trouble with the with-Nazis for this, but I came up with what I think is a cool class definition pattern for Prototype, that gives you visibility over Class attributes, similar to what you would experience in more static languages: var Foo = Class.create(); Object.extend(Foo, { A_CLASS_CONSTANT: 42, a_class_method: function() { } }); with (Foo) addMethods({ an_instance_method: function() { alert(A_CLASS_CONSTANT); a_class_method(); } }); Apart from the usual ''with'' pitfalls, it''s pretty clean. Any thoughts? --~--~---------~--~----~------------~-------~--~----~ 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, Then you''ll probably enjoy this thread: http://groups.google.com/group/rubyonrails-spinoffs/browse_thread/thread/db7fd3d685bb41c2# -- T.J. Crowder tj / crowder software / com On May 22, 3:09 pm, Frederick Polgardy <f...-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org> wrote:> I might get in trouble with the with-Nazis for this, but I came up > with what I think is a cool class definition pattern for Prototype, > that gives you visibility over Class attributes, similar to what you > would experience in more static languages: > > var Foo = Class.create(); > Object.extend(Foo, { > A_CLASS_CONSTANT: 42, > a_class_method: function() { > }}); > > with (Foo) addMethods({ > an_instance_method: function() { > alert(A_CLASS_CONSTANT); > a_class_method(); > } > > }); > > Apart from the usual ''with'' pitfalls, it''s pretty clean. > > Any thoughts?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It does look elegant. Take a look at this article, where "with" is used in a similar manner to simulate "private static" members: http://www.litotes.demon.co.uk/js_info/private_static.html Best, kangax On May 22, 10:09 am, Frederick Polgardy <f...-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org> wrote:> I might get in trouble with the with-Nazis for this, but I came up > with what I think is a cool class definition pattern for Prototype, > that gives you visibility over Class attributes, similar to what you > would experience in more static languages: > > var Foo = Class.create(); > Object.extend(Foo, { > A_CLASS_CONSTANT: 42, > a_class_method: function() { > }}); > > with (Foo) addMethods({ > an_instance_method: function() { > alert(A_CLASS_CONSTANT); > a_class_method(); > } > > }); > > Apart from the usual ''with'' pitfalls, it''s pretty clean. > > Any thoughts?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Very interesting and long. Thanks! Although when you need 85% comments to explain what the other 15% of the code is doing, that smells like a readability problem. ;-) -Fred On Thu, May 22, 2008 at 1:02 PM, kangax <kangax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Take a look at this article, where "with" is used in a similar manner > to simulate "private static" members: > http://www.litotes.demon.co.uk/js_info/private_static.html >-- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---