Topic awaiting preservation: OO-style event-based "this" question (Page 1 of 1) |
|
---|---|
Bipolar (III) Inmate From: schillmania.com |
posted 04-05-2003 16:54
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 |
posted 04-05-2003 17:24
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 |
posted 04-05-2003 21:02
Slime, |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 04-05-2003 22:17
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 |
posted 04-07-2003 13:11
Damn, how come Opera's back-button doesn't work?! Well, I'll just try again: |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 04-07-2003 18:01
By the way, declaring |
Bipolar (III) Inmate From: schillmania.com |
posted 04-07-2003 22:43
Thanks for the insight. |