This decoupling would in theory allow you to switch out a base library without needing to rewrite your application modules. However in practice this seems to be more difficult to implement.
There are concrete implementations of this proposed architecture, such as AuraJS . However from looking at the source it seems that the sandbox still has leaky abstractions by returning jQuery objects from some of its methods.
I'm not concerned with AuraJS specifically, but more the general concept of trying to abstract a library like jQuery without losing so much functionality.
As an example, say my facade/sandbox has a dom method
. I can think of 3 options for what it might return:
A jQuery object - This would leak jQuery out into the consuming modules.
A raw dom element - Loss of functionality, nobody really wants to work with this! No chaining.
A custom jQuery-like wrapper - Could be quite complex, but seems like the ideal solution.
So my question is, how would you abstract a library like jQuery without losing too much functionality, such that it could be replaced at some point in the future with minimal effort?