I'm trying to create a JavaScript object that creates a set of DOM elements (IMG tags to be specific) -- four functions (methods) are part of the object, one builds the group of icons, three are event handlers: Click, MouseOver, and MouseOut.
To properly define the event handlers, I need to know the name of the local variable that is the instance of my object, but can find no way to determine it.
In the web page:
...
var ip = new IconPicker(...)
... </script> ...
<li><a href="#" onclick="ip.buildIt("daImageBox"); return false;">boB's Icon Picker</a> <div id="daImageBox" class="iconPickBox" hidden></div> </li>
In the js file:
function IconPicker(...) { ... }
IconPicker.prototype.imageClicked = function(ctrl) { ... }
IconPicker.prototype.buildIt(divName) {
... "<img ... onClick='___.imageClicked(this)' ... />"
In this example, the ___ needs to be filled in with "ip" -- but how to determine that???
Assume there's a CSS file with the classes et al defined.
The uber-tricky part (or likely simple if one already knows the trick) is that all three handlers need a parameter that is the DOM instance of the clicked (or hovered) component.
This is communicated above with the 'this' parameter to the imageClicked() call -- but 'this' has a different meaning inside an object method, and what I'm slamming into is the dual-need in the same definition: I need this handler method to be sent 'this' parameter.
Granted, determining the name of the instance variable is a cheesy, hacky solution -- but it would solve the problem.
IconPickerinstances for which a similar thing needs to be done? Can you post the context of wherebuildItis invoked?