Replacing or wrapping component constructor functions
Created by: michaek
Bootstrap components are defined as constructor functions in a private scope. While they are exposed globally within $.fn
, they are called with references to those constructors within that private scope.
That means that there's no way to replace or wrap the code within the constructor function from 3rd party code. The use case that I'm imagining: modifying the behavior of the stock components without maintaining a fork of Bootstrap.
The design that seems appropriate is moving the code from within the constructor functions into an init method on the constructor's prototype, leaving all constructor functions looking something like this:
var Affix = function (element, options) {
this.init(element, options);
}
That would allow global access to override the init method, via $.fn.affix.Constructor.init
which would also affect the reference to the constructor as Affix
within its private scope. The change should not affect any functionality or the API beyond exposing the constructor function for manipulation. If this sounds good, I'll be happy to make a PR.
I apologize if this is revisiting an old question that's been resolved - I wasn't able to find historical work on this, but I know that doesn't mean it's not out there!