Underscore.js and noconflict

风格不统一 提交于 2019-12-13 02:34:18

问题


Writing a third-party javascript code which uses underscore.js and tries to avoid conflicts with the underscore.js version that might be used on the main site. So, my naive code is like this:

window.$MyUS = _.noConflict();

I use $MyUS instead of _ from now on. Unfortunately, on some sites I receive the following error:

Uncaught ReferenceError: _ is not defined

What am I doing wrong?


回答1:


There was a global exports object defined, which prevented the underscore.js to be installed properly. The object has two functions declared: compile() and compileToString(). The functions' implementation reveals the LF object which is most likely belongs to LiveFyre Javascript API: http://www.livefyre.com/docs/javascript-sdk-reference.

That's the investigation about the unsuccessful underscore.js installation. Still puzzled on what shall I do now and how to resolve it properly: underscore.js, global object named "exports" and livefyre javascript API - integration conflict.



来源:https://stackoverflow.com/questions/11609415/underscore-js-and-noconflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!