Can I increase the scope of 'this' in the following example?
- by Stomped
In using a jquery callback, I found that 'this' isn't defined anymore. I've found a work around, which is to set 'this' to another variable. For example, like so:
function handler(DATA) {
myThis = this;
$.post(
'file.php',
DATA,
function() {
// THIS where I need access to 'this', but its not available
// unless I've used the 'myThis' trick above
}
);
}
It works like this, but I am always looking for 'the right way' or 'the better way' to do things.
Is this the best way? or is there another?