From docs I understand that .proxy() would change the scope of the function passed as an argument. Could someone please explain me this better? Why should we do
The same goal can be achieved using a "Immediately-Invoked Function Expression, short: IIFE" self executing function:
$('#myElement').click(function() {
(function(el){
setTimeout(function() {
// Problem! In this function "this" is not our element!
el.addClass('colorme');
}, 1000);
})($(this)); // self executing function
});
.colorme{
color:red;
font-size:20px;
}
JS Bin
Click me