mediawiki.widgets: Remove use of bind() for lexical 'this' binding
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 25 Mar 2016 00:35:39 +0000 (00:35 +0000)
committerBartosz Dziewoński <matma.rex@gmail.com>
Fri, 25 Mar 2016 13:48:10 +0000 (13:48 +0000)
commitbbef4902f933c7221de83d76ead61b0ac44b5794
tree3e9580ba90d6ec2a98a0191eb404d9eaab31e979
parent34dc7a297facc702593aa0460056607b0cf91326
mediawiki.widgets: Remove use of bind() for lexical 'this' binding

Follows-up 4636ac79dd.

Bind can be useful when needing to pass an instance method elewhere.

However when nesting closures, use the scope directly instead of binding 'this'
several layers deep. This is fragile at best and doesn't make it less confusing.

Leave the natural 'this' unchanged. Change this can go wrong both ways and
results in unpredictable behaviour and confusing code that is hard to review.
Sometimes one means the outer 'this' but gets the inner one, and sometimes you
need the inner one (e.g. inside callbacks for jQuery). Consistently assign a
variable and use scope to access objects. Besides, one can't escape it when you
need both.

This avoids an entire class of potential errors. It also performs marginally
better without a binding but that's besides the point as there are other valid
uses of bind().

Change-Id: I1fcfdbd8fa7c52e150cadd8a520591e700c5bfa9
resources/src/mediawiki.widgets/mw.widgets.CategoryCapsuleItemWidget.js