Hi, I''m relatively new to javascript programming, and OOP in general, so please be nice to me ;) My question is: I''d like to extend the Form class in prototype to have a Disable function that will disable all of the fields in a form. I''ve already written a function to do this, but I''d like to include it in my own library so I can access it easily and also so it lies within a namespace. I know I can just modify prototype.js to do this, but I''d rather not, if possible, so I can easily update prototype without having to worry about adding my code back in. I have something like this in my html files: <script type="text/javascript" src="prototype.js"></script> <script type="text/javascript" src="libkitchen.js"></script> if possible, I''d like to put the extension of the class into libkitchen.js If nothing else, if you could toss me in the direction of something to read or an example to look at, I will figure it out :) Thanks in advance, and thanks for prototype, it really is an amazing example of javascript :) -Jeremy _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
The prototype lib already has the enable and disable functions for the Form class to do what you want. On 12/15/05, Jeremy Kitchen <kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org> wrote:> Hi, I''m relatively new to javascript programming, and OOP in general, so > please be nice to me ;) > > My question is: > I''d like to extend the Form class in prototype to have a Disable function that > will disable all of the fields in a form. > > I''ve already written a function to do this, but I''d like to include it in my > own library so I can access it easily and also so it lies within a namespace. > > I know I can just modify prototype.js to do this, but I''d rather not, if > possible, so I can easily update prototype without having to worry about > adding my code back in. > > I have something like this in my html files: > <script type="text/javascript" src="prototype.js"></script> > <script type="text/javascript" src="libkitchen.js"></script> > > if possible, I''d like to put the extension of the class into libkitchen.js > > If nothing else, if you could toss me in the direction of something to read or > an example to look at, I will figure it out :) > > Thanks in advance, and thanks for prototype, it really is an amazing example > of javascript :) > > -Jeremy > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > >
On Thursday 15 December 2005 17:56, Andrew Kaspick wrote:> The prototype lib already has the enable and disable functions for the > Form class to do what you want.hmm... you''re right :) well, let''s say hypothetically I want to extend one of prototype''s classes with a function, how would I go about doing that? -Jeremy _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On Friday 16 December 2005 03:19, Jeremy Kitchen wrote:> On Thursday 15 December 2005 17:56, Andrew Kaspick wrote: > > The prototype lib already has the enable and disable functions for > > the Form class to do what you want. > > hmm... you''re right :) > > well, let''s say hypothetically I want to extend one of prototype''s > classes with a function, how would I go about doing that?Form.foo = function(element) { ... }; Form.Element.bar = function(element) { ... }; etc. Note that these are *not* classes. A class is something that can have exemplars. That''s not the case with Form, Form.Element and all the others. What you see here is the JavaScript way of implementing namespaces. In prototype.js look for Class.create() to see cases where classes are implemented. In general, JavaScript doesn''t have classes as language constructs. Instead, it has prototypes. Prototype.js uses prototypes to create something resembling classes in other OOPLs. Michael -- Michael Schuerig Face reality and stare it down mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org --Jethro Tull, Silver River Turning http://www.schuerig.de/michael/
> Note that these are *not* classes. A class is something that can have > exemplars. That''s not the case with Form, Form.Element and all the > others.I wish there was more consistency in scriptaculous in this regard. Why Sortable.create(''el''), but new Effect.Highlight(''el'')? I''m sure there''s a reason, but I couldn''t fathom a guess. I''m thinking maybe I''ll make an extension that creates classes to be used for things like Sortable. It''ll just be a wrapper into the other function calls. Then I can say new Sortable(''el'') like I keep doing on accident, but it''ll actually work. Greg
That''s because Sortables need to be updatable, and some Object (the Sortable object in this case) needs to hold information about which options where used for creating them. Maybe it''s something for scriptaculous 2 to have a more consistant API here. -Thomas Am 16.12.2005 um 16:05 schrieb Gregory Hill:> >> Note that these are *not* classes. A class is something that can have >> exemplars. That''s not the case with Form, Form.Element and all the >> others. > > I wish there was more consistency in scriptaculous in this regard. > Why > Sortable.create(''el''), but new Effect.Highlight(''el'')? I''m sure > there''s > a reason, but I couldn''t fathom a guess. I''m thinking maybe I''ll make > an extension that creates classes to be used for things like Sortable. > It''ll just be a wrapper into the other function calls. > > Then I can say new Sortable(''el'') like I keep doing on accident, but > it''ll actually work. > > Greg > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Makes sense, but perhaps you could have a Sortable class that appends itself to a container class when instantiated. Then I could still say new Sortable and Sortable.initialize would take care of making sure it got into the right container. Anyhoo, I didn''t mean offense by my comments, just frustration at typing the wrong thing over and over :) Greg> -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org[mailto:rails-spinoffs-> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Thomas Fuchs > Sent: Friday, December 16, 2005 8:16 AM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails-spinoffs] Re: extending prototype''s classes > > That''s because Sortables need to be updatable, and some Object (the > Sortable object in this case) needs to hold information about which > options where used for creating them. > > Maybe it''s something for scriptaculous 2 to have a more consistant > API here. > > -Thomas > > Am 16.12.2005 um 16:05 schrieb Gregory Hill: > > > > >> Note that these are *not* classes. A class is something that canhave> >> exemplars. That''s not the case with Form, Form.Element and all the > >> others. > > > > I wish there was more consistency in scriptaculous in this regard. > > Why > > Sortable.create(''el''), but new Effect.Highlight(''el'')? I''m sure > > there''s > > a reason, but I couldn''t fathom a guess. I''m thinking maybe I''llmake> > an extension that creates classes to be used for things likeSortable.> > It''ll just be a wrapper into the other function calls. > > > > Then I can say new Sortable(''el'') like I keep doing on accident, but > > it''ll actually work. > > > > Greg > > _______________________________________________ > > 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