4 ms·
Do JSLint or JSHint catch the common error of using "this" inside a closure when you want it to be lexically bound instead of dynamically? It's easy to forget
by SimHacker 15y ago
Do JSLint or JSHint catch the common error of using "this" inside a closure when you want it to be lexically bound instead of dynamically?
It's easy to forget to go "var me = this;" and use me instead of this inside of closures. But how would JSLint or JSHint know you made a mistake and didn't actually mean for "this" to be bound dynamically?
- mark_story 15y agoNo, because this is still valid inside the anonymous function. It can't tell which this you intended to get. It would be able to find out if you used an uninitialized me, _this, that though and complain. Using self as the this alias is really dangerous as it leaks to window.self so avoid it like the plague.