Flotr2 conflict with latest version of Underscore

207 Views Asked by At

Flotr2 has dependency of underscore and it also ships with older version of underscore(1.1.7) but my project requires latest version of underscore (1.7.0) and both thing conflicts.

Is there any work around? Thanks in advance.

1

There are 1 best solutions below

1
On

Flotr2 by the looks of it only uses a portion of underscore (that probably being the reason the dev chose to include it in the source).

Generally speaking javascript is perfectly fine with overwriting global variables. Meaning not that you should make a habit of it, but that it's syntactically legal. Thus you can simply include the latest underscore after you've imported Flotr2:

<script src="lib/flotr2.min.js"></script>
<script src="lib/underscore.min.js"></script>

Here's a fiddle based off of the Flotr2 docs demonstrating this (console should be printing Underscore's version as 1.7 -- notice that if you swap the two <script> tags it will print 1.1.7 as Flotr2's import will overwrite the global _)

CDN friendly version: http://jsfiddle.net/jfmdz399/ (/1/)