我正在玩html5 LeanBack播放器,它在页面上只有它的javascritpts时效果很好。但是,如果我将这些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’
在函数LBPlayer.prototype.resolveTextPlainSubs。
中我猜这是因为与rails中的原生Prototype冲突,但我不知道如何解决它。 感谢
答案 0 :(得分:1)
事实上,它与Array.prototype
// 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 = "";
为了解决这个问题,您应该使用简单的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 = "";
...
}