Underscore.js 和 noconflict [英] Underscore.js and noconflict

查看:20
本文介绍了Underscore.js 和 noconflict的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写第三方 javascript 代码,该代码使用 underscore.js 并尝试避免与 underscore.js 版本发生冲突,可能在主站点上使用.所以,我的天真代码是这样的:

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();

我从现在开始使用 $MyUS 而不是 _.不幸的是,在某些网站上,我收到以下错误:

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

未捕获的引用错误:_ 未定义

Uncaught ReferenceError: _ is not defined

我做错了什么?

推荐答案

定义了一个全局的 exports 对象,导致 underscore.js 无法正确安装.该对象声明了两个函数:compile()compileToString().这些函数的实现揭示了最有可能属于 LiveFyre Javascript API 的 LF 对象:http://www.livefyre.com/docs/javascript-sdk-reference.

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.

这是关于underscore.js 安装不成功的调查.仍然对我现在该怎么做以及如何正确解决它感到困惑:underscore.js,名为exports"的全局对象;和 livefyre javascript API - 集成冲突.

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.

这篇关于Underscore.js 和 noconflict的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆