Event.observe(window, 'load', function() {
   this.myField = new Field();
}.bind(myObject));// assuming myObject is of type MyClass

On Aug 23, 6:16 am, JoJo <tokyot...@gmail.com> wrote:
> May I get some help with the actual coding? I tried the following and
> myField is still null when used by other methods in the class.
>
> Event.observe(window, 'load', function() {
>    this.myField = new Field();
>
> }.bind(MyClass));
>
> On Aug 22, 7:42 pm, DJ Mangus <d.man...@gmail.com> wrote:
>
>
>
> > Everything in js is an object. Even function literals.
>
> > On 8/22/09, JoJo <tokyot...@gmail.com> wrote:
>
> > > How do I use bind? Doesn't the bind function take an object as an
> > > argument? I'm doing this stuff inside a class, not an object.
>
> > > On Aug 22, 6:15 pm, Gareth Evans <agr...@gmail.com> wrote:
> > >> Use bind (method on the function object)
> > >> see the typewriter example i wrote for syntax
>
> > >> On Sun, Aug 23, 2009 at 9:06 AM, Mojito <tokyot...@gmail.com> wrote:
>
> > >> > MyClass = Class.create({
> > >> >   initialize: function() {
> > >> >      this.myField = null;
> > >> >      Event.observe(window, 'load', function() {
> > >> >         this.myField = new Field();
> > >> >      });
> > >> >   },
> > >> >   myMethod: function() {
> > >> >      alert(this.myField);
> > >> >   }
> > >> > });
>
> > >> > +++++++++++++++++++++++++++++++
>
> > >> > Field's constructor uses Scriptaculous's sliders, which require an
> > >> > element to be already loaded.  That's why I'm only setting
> > >> > this.myField when the window has loaded.  I see that my sliders get
> > >> > initialized properly, but this.myField is still null when I call
> > >> > myMethod().  I suspect this has something to do with the "this" scope
> > >> > in my anonymous function.  How do I fix this to do what I intended?
>
> > --
> > Sent from my mobile device

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to