[英]Conflict of two javascript files
I'm playing with html5 LeanBack Player and it works well when on the page only its javascritpts. 我正在使用html5 LeanBack Player,当仅在页面上使用它的javascritpts时,它可以很好地工作。 But if I add these javascript files to rails 3 project then I get error in LeanBack Player's javascript file: 但是,如果我将这些JavaScript文件添加到Rails 3项目中,则LeanBack Player的javascript文件会出现错误:
Uncaught TypeError: Object function each(iterator, context) {
var index = 0;
try {
this._each(function(value) {
iterator.call(context, value, index++);
});
} catch (e) {
if (e != $break) throw e;
}
return this;
} has no method ‘split’
in function LBPlayer.prototype.resolveTextPlainSubs. 在函数LBPlayer.prototype.resolveTextPlainSubs中。
I guessed that's because of conflict with native Prototype in rails but I don't know how to resolve it. 我猜想那是因为与Rails中的原生Prototype冲突,但是我不知道如何解决它。 Thanks 谢谢
Indeed it's a conflict with Prototypes extending of Array.prototype
: 确实,这与Array.prototype
扩展的Prototypes冲突:
// leanbackPlayer.js @941
srt = srt.split('\n\n');
var i = 0; var isSub = false;
this.vars.subs[lang] = {};
this.vars.subs[lang].label = {};
this.vars.subs[lang].label = label;
this.vars.subs[lang].track = {};
// Error: using for in over an array is just stupid
// not even using hasOwnProperty is outright pitiful
for(var s in srt) {
// this will also yield `each` but that's a function which has no .split() method
var st = srt[s].split('\n');
var time; var j;
if(st.length >= 2) {
var t = "";
In order to fix it you should replace the for(var s in srt)
with a simple for loop: 为了修复它,您应该使用简单的for循环替换for(var s in srt)
:
for(var e = 0, el = srt.length; e < el; e++) {
var st = srt[e].split('\n');
var time; var j;
if(st.length >= 2) {
var t = "";
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.