Hello Everyone, I am working on a control collection for javascript/Ajax.Net. I am stuck on the class inheritance aspects of the prototype library. If someone could point me to an example it would be a great help. I have looked through the controls.js of the scriptaculous library and found something like the below code, but everytime I ran it I would get a constructor error. Thanks for any help; Looking for something like: MyControls.TextBox = Class.create(); MyControls.TextBox.prototype { baseInitialize: function(loadCallback, saveCallback, saveOptions) { this.loadCallback = loadCallback; this.saveCallback = saveCallback; .... }, Save: function() { //do save operation using options } }; MyControls.EditableTextBox = Class.create(); Object.extend(MyControls.EditableTextBox.prototype, MyControls.TextBox.prototype), { initialize: function(targetObj, loadCallback, saveCallBack, options) { this.baseInitialize(loadCallback, saveCallback); }, Update: function() { this.Save(); } } _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
You''re missing a level of extension in the 2nd object. It should be... Object.extend(Object.extend(MyControls.EditableTextbox.prototype, MyControls.TextBox.prototype), { ...stuff here... }); ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of John Osborn Sent: Friday, February 10, 2006 1:45 PM To: Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] Prototype Inheritance example Hello Everyone, I am working on a control collection for javascript/Ajax.Net. I am stuck on the class inheritance aspects of the prototype library. If someone could point me to an example it would be a great help. I have looked through the controls.js of the scriptaculous library and found something like the below code, but everytime I ran it I would get a constructor error. Thanks for any help; Looking for something like: MyControls.TextBox = Class.create(); MyControls.TextBox.prototype { baseInitialize: function(loadCallback, saveCallback, saveOptions) { this.loadCallback = loadCallback; this.saveCallback = saveCallback; .... }, Save: function() { //do save operation using options } }; MyControls.EditableTextBox = Class.create(); Object.extend(MyControls.EditableTextBox.prototype , MyControls.TextBox.prototype), { initialize: function(targetObj, loadCallback, saveCallBack, options) { this.baseInitialize(loadCallback, saveCallback); }, Update: function() { this.Save(); } } The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Ryan, Thank you for the quick response. I tried what you suggested and still no luck. I also found in scriptaculous.js another example of inheritance that might also work: Autocompleter.Local = Class.create(); Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), { ..stuff }); But that also did not work. Maybe I am creating the base class incorrectly? There error I keep getting is: MyObject.SubObject is not a constructor (firefox latest) Thanks again for any help. On 2/10/06, Ryan Gahl <Ryan.Gahl@camtronics.com> wrote:> > You're missing a level of extension in the 2nd object. It should be… > > > > Object.extend(Object.extend(MyControls.EditableTextbox.prototype, > MyControls.TextBox.prototype), > > { > > …stuff here… > > }); > > > ------------------------------ > > *From:* rails-spinoffs-bounces@lists.rubyonrails.org [mailto: > rails-spinoffs-bounces@lists.rubyonrails.org] *On Behalf Of *John Osborn > *Sent:* Friday, February 10, 2006 1:45 PM > *To:* Rails-spinoffs@lists.rubyonrails.org > *Subject:* [Rails-spinoffs] Prototype Inheritance example > > > > Hello Everyone, > > I am working on a control collection for javascript/Ajax.Net. I am stuck > on the class inheritance aspects of the prototype library. If someone could > point me to an example it would be a great help. I have looked through the > controls.js of the scriptaculous library and found something like the > below code, but everytime I ran it I would get a constructor error. > > Thanks for any help; > > *Looking for something like: * > > MyControls.TextBox = Class.create(); > MyControls.TextBox.prototype > { > baseInitialize: function(loadCallback, saveCallback, saveOptions) > { > this.loadCallback = loadCallback; > this.saveCallback = saveCallback; > .... > }, > > Save: function() > { > //do save operation using options > } > }; > > MyControls.EditableTextBox = Class.create(); > > Object.extend(MyControls.EditableTextBox.prototype , > MyControls.TextBox.prototype), > { > initialize: function(targetObj, loadCallback, saveCallBack, options) > { > this.baseInitialize(loadCallback, saveCallback); > }, > > Update: function() > { > this.Save(); > } > } > > The information transmitted in this electronic mail is intended only for > the person or entity to which it is addressed and may contain confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient is > prohibited. If you received this in error, please contact the sender and > delete the material from all computers. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >-- that's how i roll, jx _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 2/10/06, John Osborn <ozzy.osborn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thank you for the quick response. I tried what you suggested and still no > luck. I also found in scriptaculous.js another example of inheritance that > might also work: > > Autocompleter.Local = Class.create(); > Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), > { > ..stuff > }); > > But that also did not work. Maybe I am creating the base class incorrectly? > There error I keep getting is: MyObject.SubObject is not a constructor > (firefox latest)I hope that''s a rhetorical question ... you haven''t shown us how you''re creating your base class and you haven''t provided us with a live site that we can explore on our own. To finish the Autocompleter.Local example you provided: var Autocompleter = {} Autocompleter.Base = function() {}; Autocompleter.Base.prototype = { <snip> } Todd
If my suggestion did not work then my next thought is that you are not actually defining "MyControls" first. You can''t define MyControls.TextBox is MyControls is not defined. _____ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of John Osborn Sent: Friday, February 10, 2006 4:00 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] Prototype Inheritance example Ryan, Thank you for the quick response. I tried what you suggested and still no luck. I also found in scriptaculous.js another example of inheritance that might also work: Autocompleter.Local = Class.create(); Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), { ..stuff }); But that also did not work. Maybe I am creating the base class incorrectly? There error I keep getting is: MyObject.SubObject is not a constructor (firefox latest) Thanks again for any help. On 2/10/06, Ryan Gahl <Ryan.Gahl-nlycWCgr5/vuufBYgWm87A@public.gmane.org > wrote: You''re missing a level of extension in the 2nd object. It should be. Object.extend(Object.extend(MyControls.EditableTextbox.prototype, MyControls.TextBox.prototype), { .stuff here. }); _____ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of John Osborn Sent: Friday, February 10, 2006 1:45 PM To: Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] Prototype Inheritance example Hello Everyone, I am working on a control collection for javascript/Ajax.Net. I am stuck on the class inheritance aspects of the prototype library. If someone could point me to an example it would be a great help. I have looked through the controls.js of the scriptaculous library and found something like the below code, but everytime I ran it I would get a constructor error. Thanks for any help; Looking for something like: MyControls.TextBox = Class.create(); MyControls.TextBox.prototype { baseInitialize: function(loadCallback, saveCallback, saveOptions) { this.loadCallback = loadCallback; this.saveCallback = saveCallback; .... }, Save: function() { //do save operation using options } }; MyControls.EditableTextBox = Class.create(); Object.extend(MyControls.EditableTextBox.prototype , MyControls.TextBox.prototype), { initialize: function(targetObj, loadCallback, saveCallBack, options) { this.baseInitialize(loadCallback, saveCallback); }, Update: function() { this.Save(); } } The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs -- that''s how i roll, jx The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Ryan: No I am defining that with a var -- besides I would get a differant error that blah.blah is not a contructor Todd: The skeleton code I am using to create the base class is in my first email. On 2/10/06, Ryan Gahl <Ryan.Gahl@camtronics.com> wrote:> > If my suggestion did not work then my next thought is that you are not > actually defining "MyControls" first. > > > > You can't define MyControls.TextBox is MyControls is not defined. > > > ------------------------------ > > *From:* rails-spinoffs-bounces@lists.rubyonrails.org [mailto: > rails-spinoffs-bounces@lists.rubyonrails.org] *On Behalf Of *John Osborn > *Sent:* Friday, February 10, 2006 4:00 PM > *To:* rails-spinoffs@lists.rubyonrails.org > *Subject:* Re: [Rails-spinoffs] Prototype Inheritance example > > > > Ryan, > > Thank you for the quick response. I tried what you suggested and still no > luck. I also found in scriptaculous.js another example of inheritance that > might also work: > > Autocompleter.Local = Class.create(); > Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), > { > ..stuff > }); > > But that also did not work. Maybe I am creating the base class > incorrectly? > There error I keep getting is: MyObject.SubObject is not a constructor > (firefox latest) > > Thanks again for any help. > > On 2/10/06, *Ryan Gahl* <Ryan.Gahl@camtronics.com > wrote: > > You're missing a level of extension in the 2nd object. It should be… > > > > Object.extend(Object.extend(MyControls.EditableTextbox.prototype, > MyControls.TextBox.prototype), > > { > > …stuff here… > > }); > > > ------------------------------ > > *From:* rails-spinoffs-bounces@lists.rubyonrails.org [mailto: > rails-spinoffs-bounces@lists.rubyonrails.org] *On Behalf Of *John Osborn > *Sent:* Friday, February 10, 2006 1:45 PM > *To:* Rails-spinoffs@lists.rubyonrails.org > *Subject:* [Rails-spinoffs] Prototype Inheritance example > > > > Hello Everyone, > > I am working on a control collection for javascript/Ajax.Net. I am stuck > on the class inheritance aspects of the prototype library. If someone could > point me to an example it would be a great help. I have looked through the > controls.js of the scriptaculous library and found something like the > below code, but everytime I ran it I would get a constructor error. > > Thanks for any help; > > *Looking for something like: * > > MyControls.TextBox = Class.create(); > MyControls.TextBox.prototype > { > baseInitialize: function(loadCallback, saveCallback, saveOptions) > { > this.loadCallback = loadCallback; > this.saveCallback = saveCallback; > .... > }, > > Save: function() > { > //do save operation using options > } > }; > > MyControls.EditableTextBox = Class.create(); > > Object.extend(MyControls.EditableTextBox.prototype , > MyControls.TextBox.prototype), > { > initialize: function(targetObj, loadCallback, saveCallBack, options) > { > this.baseInitialize(loadCallback, saveCallback); > }, > > Update: function() > { > this.Save(); > } > } > > The information transmitted in this electronic mail is intended only for > the person or entity to which it is addressed and may contain confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient is > prohibited. If you received this in error, please contact the sender and > delete the material from all computers. > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > -- > that's how i roll, > jx > > The information transmitted in this electronic mail is intended only for > the person or entity to which it is addressed and may contain confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient is > prohibited. If you received this in error, please contact the sender and > delete the material from all computers. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.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
Ok then, the other thing then is your MyControls.TextBox doesn''t seem to have an "initialize" method. That might have something to do with it. Try this, change "baseInitialize to initialize. Then you will have instantiate your base class in your subclass''s initialize method to inherit, like so. MyControls.TextBox = Class.create(); MyControls.TextBox.prototype { initialize: function(loadCallback, saveCallback, saveOptions) { Blah blah blah. } }; MyControls.EditableTextBox = Class.create(); MyControls.EditableTextBox.prototype = { initialize: function(targetObj, loadCallback, saveCallBack, options) { Object.extend(this, new MyControls.TextBox(loadCallback, saveCallBack) ); . .blah blah blah. } }; If that doesn''t work I seriously don''t know what''s going on then. If you try that and still have problems, then we''ll need more code from your project or a test page somewhere, as Todd Ross said, in order to help you further. _____ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of John Osborn Sent: Friday, February 10, 2006 4:21 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] Prototype Inheritance example Ryan: No I am defining that with a var -- besides I would get a differant error that blah.blah is not a contructor Todd: The skeleton code I am using to create the base class is in my first email. On 2/10/06, Ryan Gahl <Ryan.Gahl-nlycWCgr5/vuufBYgWm87A@public.gmane.org> wrote: If my suggestion did not work then my next thought is that you are not actually defining "MyControls" first. You can''t define MyControls.TextBox is MyControls is not defined. _____ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of John Osborn Sent: Friday, February 10, 2006 4:00 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] Prototype Inheritance example Ryan, Thank you for the quick response. I tried what you suggested and still no luck. I also found in scriptaculous.js another example of inheritance that might also work: Autocompleter.Local = Class.create(); Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), { ..stuff }); But that also did not work. Maybe I am creating the base class incorrectly? There error I keep getting is: MyObject.SubObject is not a constructor (firefox latest) Thanks again for any help. On 2/10/06, Ryan Gahl <Ryan.Gahl-nlycWCgr5/vuufBYgWm87A@public.gmane.org > wrote: You''re missing a level of extension in the 2nd object. It should be. Object.extend(Object.extend(MyControls.EditableTextbox.prototype, MyControls.TextBox.prototype), { .stuff here. }); _____ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of John Osborn Sent: Friday, February 10, 2006 1:45 PM To: Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] Prototype Inheritance example Hello Everyone, I am working on a control collection for javascript/Ajax.Net. I am stuck on the class inheritance aspects of the prototype library. If someone could point me to an example it would be a great help. I have looked through the controls.js of the scriptaculous library and found something like the below code, but everytime I ran it I would get a constructor error. Thanks for any help; Looking for something like: MyControls.TextBox = Class.create(); MyControls.TextBox.prototype { baseInitialize: function(loadCallback, saveCallback, saveOptions) { this.loadCallback = loadCallback; this.saveCallback = saveCallback; .... }, Save: function() { //do save operation using options } }; MyControls.EditableTextBox = Class.create(); Object.extend(MyControls.EditableTextBox.prototype , MyControls.TextBox.prototype), { initialize: function(targetObj, loadCallback, saveCallBack, options) { this.baseInitialize(loadCallback, saveCallback); }, Update: function() { this.Save(); } } The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs -- that''s how i roll, jx The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 2/10/06, John Osborn <ozzy.osborn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Todd: The skeleton code I am using to create the base class is in my first > email.Sorry. I was expecting to see MyControls.Base. http://www.brainsick.com/prototype/classinheritance.html There were a couple changes. Like Ryan said, you need to Object.extend() twice. I broke them into two separate commands instead of trying to stack them. There were some syntax errors in your examples ... a missing ); after the Object.extends. You don''t need to Class.create() your ''Base'' (MyControls.TextBox). Class.create() just returns an object that calls (object).initialize() automatically, which you don''t need to do for your base. You also had a saveCallback vs saveCallBack problem. Does this help? Todd
Thanks for all you help and quick replies. It is still not working but it must be a syntax error or something I will have to look at it later. Thanks. On 2/10/06, Todd Ross <rails-spinoffs-25kFIyuv2iRiLUuM0BA3LQ@public.gmane.org> wrote:> > On 2/10/06, John Osborn <ozzy.osborn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Todd: The skeleton code I am using to create the base class is in my > first > > email. > > Sorry. I was expecting to see MyControls.Base. > > http://www.brainsick.com/prototype/classinheritance.html > > There were a couple changes. Like Ryan said, you need to > Object.extend() twice. I broke them into two separate commands > instead of trying to stack them. > > There were some syntax errors in your examples ... a missing ); after > the Object.extends. > > You don''t need to Class.create() your ''Base'' (MyControls.TextBox). > Class.create() just returns an object that calls (object).initialize() > automatically, which you don''t need to do for your base. > > You also had a saveCallback vs saveCallBack problem. > > Does this help? > > Todd > _______________________________________________ > 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