I find myself wanting to re-define "this" many times through the day. Could someone please tell me how to achieve this or why I cannot?
For example:
this = $('div')[0];
Why i would like to do this: working with 'this' is more natural then passing a reference through a function call. 'this' should refer to the calling object inside of a function for example:
var my_div = $('#some_div');
my_div.click(function(){
console.log(this);
});
What gets sent to the log is a reference to the window not to the div that is calling the function.
Every onchange event handler I write is forced to take 'this' as a parameter in order to maintain reference to the calling object. To me this seems broken.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…