Discussion:
js/dom and "this" referencing
rvj
2010-05-11 07:50:06 UTC
Permalink
According to DOM addeventlistener documentation the "this" value changes to
the
element from which the event was fired.

...so how do you (can you still) refer to the "original this element"
(initially the value of "this" is associated with the window object?)

In particular, I want to reference the value of "this" associated with an
XBL binding after one or more onload events fire

......do you have to copy/save it as a global?

... or can it be referenced using the binding id?


if so how?
Boris Zbarsky
2010-05-11 13:25:38 UTC
Permalink
Post by rvj
In particular, I want to reference the value of "this" associated with an
XBL binding after one or more onload events fire
Depends on where your listeners are coming from. Who's calling
addEventListener?

-Boris
rvj
2010-05-11 16:43:17 UTC
Permalink
just from a methods invoked initially from constructor in the binding
which may call other methods using addeventlistener

my dumb approach is just to create a common variable within the binding
constructor

thisbinding=this

and then use thisbinding rather than this instead

.. seems to work ok but just seems strange

I just thought that there might be something like top.this to refer the
bindiing xulelement

thanks anyway
Post by Boris Zbarsky
Post by rvj
In particular, I want to reference the value of "this" associated with an
XBL binding after one or more onload events fire
Depends on where your listeners are coming from. Who's calling
addEventListener?
-Boris
Boris Zbarsky
2010-05-11 17:29:30 UTC
Permalink
Post by rvj
just from a methods invoked initially from constructor in the binding
which may call other methods using addeventlistener
my dumb approach is just to create a common variable within the binding
constructor
thisbinding=this
and then use thisbinding rather than this instead
Yes, that's exactly the right approach.
Post by rvj
... seems to work ok but just seems strange
Why?
Post by rvj
I just thought that there might be something like top.this to refer the
bindiing xulelement
No.

-Boris

Continue reading on narkive:
Loading...