sure, you could do that with CS as well as there is only one me.. not that I fully understand your example.. is there only one button..? if so, why would you want to set the same event listener to it every time you hover over a div..?
because I couldn't come up with a realistic example on the spot.
In our codebase it's actually
$('.articleBlock_js').click(function(){
var me = this;
$.ajax({url: "/ajax/media.php?block=" + $(this).attr('data-id') }).done(function(data) {
$(me).val('Blocked!').css('background-color', 'red');
}
}
with AJAX you can have callbacks inside of callbacks inside of callbacks and you need to bind things to elements who have callbacks who possibly do AJAX and you need to know what this is (and sometimes you need to rebind it to something else to save it)
It forces me to be more careful. Great. One more thing to handle with care. I certainly don't have enough in my hands trying to juggle the need for good design, with my deadlines, the complications of dealing with legacy codebases, the difficulty of my problem. Now I have to make sure I never use the same variable name twice in any chain of scopes. Thank you very much, that's just what I needed, that'll prevent me from getting sloppy without a doubt.
View all comments
Show parent comment
0
u/[deleted] Jul 25 '13
[deleted] — view deleted comment