Thanks for your help. Using var obj = this works for me.

-Hector


On Tue, Nov 11, 2008 at 4:54 AM, RobG <[EMAIL PROTECTED]> wrote:

>
>
>
> On Nov 11, 5:13 pm, "Michael Geary" <[EMAIL PROTECTED]> wrote:
> > To elaborate a bit, "this" is special, but it's not magic.
> >
> > Whenever you call a function in JavaScript, it's always called as a
> method
> > of some object,
>
> No, it's not.  What object is the following functions called as
> methods of:
>
> (function(){})();
>
> function foo() {};
> foo.call({});
>
>
> > and this is a reference to that object.
>
> If an object can't be determined, the global object is used, hence:
>
>
>  var global = (function(){return this;})();
>
>
>
> > When you call foo.bar(), you are calling a function as a method of the
> foo
> > object, so this == foo.
> >
> > JavaScript also has a global object. When you call a function bar()
> without
> > any explicit object reference, you are actually calling it as a method of
> > the global object.
>
> No, they aren't.  Properties resolved on the scope chain don't behave
> like that, otherwise this used within methods found on prototype
> objects would refer to the prototype object rather than the instance.
> The global object is used when no other reference can be resolved or
> the call sets it to the this keyword.
>
>
> --
> Rob

Reply via email to