The "this" keyword is not a MooTools thing; it's a JavaScript thing. "this"
is a keyword is a reserved word in JavaScript that has a special meaning.
"this" represents, roughly, the object to which the current method belongs.
So "this" inside a class instance, by default, is that class instance.
"this" inside an array method is, by default, the array. For example:
[1,2,3].each(function(number){
alert(this.length); //3 because "this" is the array
});
You can change what "this" is by using binding. Function has a bind method
that allows you to define the "this" inside that function. Some methods
(like Array.each) allow you to pass an argument for the "this":
[1,2,3].each(function(number){
//"this" here now references 'foo'
}, foo);
On Fri, Apr 17, 2009 at 12:23 PM, csuwldcat (via Nabble) <
[email protected]<ml-user%[email protected]>
> wrote:
>
> Seriously, the base event constructor new Event([event[,win]]) talks
> about a context option. wtf, someone, anyone, Bueller?...Bueller?
> How do you set a new context for the Mootools global this internal
> keyword?
>
> I am looking at you SmarterThanMe person!
>
> - Daniel
>
>
> On Apr 16, 3:51 pm, csuwldcat
> <daniel...@...<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=2651647&i=0>>
> wrote:
> > I have never used the base Event constructor much (never had much need
> > to). However it does say this in the docs as I searched for something
> > to accomplish what I need:
> >
> > Syntax:
> >
> > new Event([event[, win]]);
> > Arguments:
> >
> > event - (event) An HTMLEvent Object.
> > win - (window, optional: defaults to window) The context of the event.
> >
> > Can someone from the dev team just give me a nod and a small example
> > one-liner of that constructor with a different context set?
> >
> > - Daniel
> >
> > On Apr 16, 3:43 pm, csuwldcat
> > <daniel...@...<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=2651647&i=1>>
> wrote:
> >
> > > If you look in the lib it uses 'this' in conjunction with many
> > > internal functions. For instance getDocument() uses this as the
> > > window reference. How do I change 'this' to reference some other
> > > object or element in the entirety of the library instance?
> >
> > > - Daniel
>
>
> ------------------------------
> View message @
> http://n2.nabble.com/-Moo--How-do-I-change-the-this-keyword-ref-in-the-Mootools-lib-object--tp2649230p2651647.html
> To start a new topic under MooTools Users, email
> [email protected]<ml-node%[email protected]>
> To unsubscribe from MooTools Users, click here< (link removed) >.
>
>
>
-----
The MooTools Tutorial: http://www.mootorial.com www.mootorial.com
Clientcide: http://www.clientcide.com www.clientcide.com
--
View this message in context:
http://n2.nabble.com/-Moo--How-do-I-change-the-this-keyword-ref-in-the-Mootools-lib-object--tp2649230p2651807.html
Sent from the MooTools Users mailing list archive at Nabble.com.