The IDE I use (Cloud 9) incorporates JSHint by giving me a warning when it detects something wrong. As a principle I try to correct my code to rectify these errors. There is one that I have now which I can't see a way around:
$("#component-manager tr:not(.edit-component) td").on("click", function() {
if ($(this).index() !== 0) {
var checkbox = $(this).parent().find("input[name=component-selected]");
checkbox.trigger("click");
}
});
This code gives me a warning: "Use of 'this
' in callback function".
I have two questions:
- What should I do to improve my code and get rid of this warning.
- Why is it better practice (for that is what JSHint tries to promote) to not use
this
in callback functions?