![]() Topic awaiting preservation: OO-style event-based "this" question (Page 1 of 1) |
|
---|---|
Bipolar (III) Inmate From: schillmania.com |
![]() A few months ago I posted a question about referring back to an OO-style JS object from an event handler using a private variable - at the time I wasn't sure if it could be done without referencing said object from a "global" scope. However, a coworker showed me this theory.. I'm not sure I understand the theory behind it, but it works. |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
![]() You're right that the "this" keyword is a reference to the image for which the event is called. However, the "self" variable will be out of scope when it's called, I think. Since it's a variable, even if it is in scope, it'll change values every time you create a new Something object. |
Bipolar (III) Inmate From: schillmania.com |
![]() Slime, |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
![]() Oh, right, that *would* make sense that the self variable works that way. The reason is that you're creating a separate onMouseOver function for each Something you create. |
Bipolar (III) Inmate From: Amsterdam |
![]() Damn, how come Opera's back-button doesn't work?! |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
![]() By the way, declaring |
Bipolar (III) Inmate From: schillmania.com |
![]() Thanks for the insight. |