There seems to be no bulletproof way to prevent conflict between underscore and lodash on the front-end.
We could do this:
<script src="/scripts/vendor/underscore/underscore.js"></script>
<script>
window._us = window._;
delete window._;
</script>
<script src="/scripts/vendor/lodash/lodash.js"></script>
but that doesn't seem to be good enough. Is there a way to use both libs or do we have to choose?
On the topic of
noConflict
, when underscore or lodash are loaded globally they will override the global_
variable. CallingnoConflict()
will reverse this, setting_
to its previous value and return the instance of_
. In the example below I commented how the global_
value will change after each action