I want to keep everything contained within a single function, and not make all the various variables global.
Is it possible to set up an event listener within the function main to watch a global var?
in this example call doTheStuff() when the index is altered? or might I be going about this the wrong way?
var index = 0;
function main(data, data, data, data, data, data,)
{
function one(){ two() }
function two(){ three() }
function three(){ }
function doTheStuff(){ }
}
There’s probably a better way to go about this, for instance:
If that doesn’t work for what you’re trying to do, you can set up an interval timer and check the value against a saved copy.
It would be possible for
indexto be changed more than once between intervals; whether that matters will depend on what you’re trying to do.Going forward, you’ll be able to do this with getters and setters on a property (part of the new ECMAScript 5 specification), but that’s still not widely-implemented. Some browsers do implement them, although with their own syntax, but others don’t (yet).