That closure vs bind
Created by: pinoniq
Is there a specific reason why the JS code of bootstrap is riddled with closures?
var that = this;
For instance the modal:
var that = this;
this.backdrop(function () {
var transition = $.support.transition && that.$element.hasClass('fade')
if (!that.$element.parent().length) {
that.$element.appendTo(that.$body) // don't move modals dom position
}
...
}
...
Modal.prototype.backdrop = function (callback) {
...
callback()
}
We are passing a callback to a method of the same object. We could remove the var that = this; and call the callable using:
callback.apply(this);
Maybe this could/should all be cleaned up.