when using prototype and Class.create(), what''s the preferred method of creating a subclass? say I have a real simple class: var Testing = Class.create(); Object.extend(Testing.prototype, { initialize: function() { ... }, ... }); would I subclass it as so? var SubClass = Class.create(); Object.extend(Object.extend(SubCLass.prototype, Testing.prototype), { ... }); or would I replace Testing.prototype above with new Testing() ? The reason I ask this is because I think I''ve seen it both ways in script.aculo.us, and they both appear to work, but I would think that creating an instance of the class might not be such a good idea because it might modify some state on the page or whatnot... Thanks :) -Jeremy -- Jeremy Kitchen ++ kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org http://ipaction.org/ -- defend your rights to fair use _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
If there is functionality in the base class''s constructor that, for instance, prepares the object instance (initializes an XHR object, etc..), or otherwise must execute, then use an instance. This is yet another "use what works for the situation" things... I use both methods frequently. I also use the instance method from within the subclass constructor sometimes (vs. from the Object.extend top portion), for instance if both constructors take arguments and the subclass needs to somehow calculate the value of one of the base class constructor''s arguments. Object.extend(SubClass.prototype, { initialize: function(id, options) { //do some stuff that determines the value of "foo" Object.extend(this, new Testing(id, options, foo)); } }); On 5/24/06, Jeremy Kitchen <kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org> wrote:> > when using prototype and Class.create(), what''s the preferred method of > creating a subclass? > > say I have a real simple class: > var Testing = Class.create(); > Object.extend(Testing.prototype, { > initialize: function() { > ... > }, > ... > }); > > would I subclass it as so? > var SubClass = Class.create(); > Object.extend(Object.extend(SubCLass.prototype, Testing.prototype), { > ... > }); > > or would I replace Testing.prototype above with new Testing() ? > > The reason I ask this is because I think I''ve seen it both ways in > script.aculo.us, and they both appear to work, but I would think that > creating an instance of the class might not be such a good idea because it > might modify some state on the page or whatnot... > > Thanks :) > > -Jeremy > > -- > Jeremy Kitchen ++ kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org > > http://ipaction.org/ -- defend your rights to fair use > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 5/24/06, Jeremy Kitchen <kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org> wrote:> when using prototype and Class.create(), what''s the preferred method of > creating a subclass?In case you are interested in this topic in general, you may like to read this great tutorial. It is not Prototype.js specific but very intersting. http://www.kevlindev.com/tutorials/javascript/inheritance/index.htm Peter
Has anyone already made available an AJAX Request Queue Object?
Hi! When starting a new thread on a mailing list, it''s best to use your MUA''s ''new'' function rather than replying to an already existing thread, removing the content of the message (including the subject) and typing your message. Threaded mail viewers and the list archives will see your message as a member of a different thread, when it is actually a new thread. Evidence: In-Reply-To: <b09d0490605242208q16b3a5d6x7c1a867aea5297dc-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> That being said: On Wednesday 24 May 2006 22:42, Maninder, Singh wrote:> Has anyone already made available an AJAX Request Queue Object?I''m not entirely sure why you would need this.... you can fire up multiple ajax calls at once and the browser will automatically handle them. Most browsers I think will send a maximum of 2 at a time, but they should get processed. If you need to use something in the return value of one ajax call in another one, simply use the first one''s onComplete callback (assuming you''re using Ajax.Request or a subclass of it) to start another ajax request. In short: What Problem Are You Trying To Solve? (tm) -Jeremy _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On Wednesday 24 May 2006 22:16, Peter Michaux wrote:> On 5/24/06, Jeremy Kitchen <kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org> wrote: > > when using prototype and Class.create(), what''s the preferred method of > > creating a subclass? > > In case you are interested in this topic in general, you may like to > read this great tutorial. It is not Prototype.js specific but very > intersting. > > http://www.kevlindev.com/tutorials/javascript/inheritance/index.htmawesome :) thanks :) -Jeremy _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On Wednesday 24 May 2006 22:08, Ryan Gahl wrote:> If there is functionality in the base class''s constructor that, for > instance, prepares the object instance (initializes an XHR object, etc..), > or otherwise must execute, then use an instance. This is yet another "use > what works for the situation" things... I use both methods frequently. > > I also use the instance method from within the subclass constructor > sometimes (vs. from the Object.extend top portion), for instance if both > constructors take arguments and the subclass needs to somehow calculate the > value of one of the base class constructor''s arguments. > > Object.extend(SubClass.prototype, { > initialize: function(id, options) { > //do some stuff that determines the value of "foo" > Object.extend(this, new Testing(id, options, foo)); > } > });this is great, this is exactly the kind of reply I was hoping for :) I never thought of having the initialize method instantiate the ''parent'' class, that''s nifty. Although I think you have the Object.extend backwards, i would think you''d do: Object.extend(new Testing(whatever), this); well, I guess it would just depend on the situation. Thanks again for the great reply :) -Jeremy _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 5/25/06, Jeremy Kitchen <kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org> wrote:> On Wednesday 24 May 2006 22:16, Peter Michaux wrote: > > On 5/24/06, Jeremy Kitchen <kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org> wrote: > > > when using prototype and Class.create(), what''s the preferred method of > > > creating a subclass? > > > > In case you are interested in this topic in general, you may like to > > read this great tutorial. It is not Prototype.js specific but very > > intersting. > > > > http://www.kevlindev.com/tutorials/javascript/inheritance/index.htm > > awesome :)I agree. That tutorial has saved me a lot of time and code. Peter