我正在使用w3c的IntersectionObserver polyfill。这个特定的line在Safari中损坏了。经调查,我发现以下代码段在Safari中不起作用,但在Chrome和Firefox中有效。是否有替代方法?我正在将0.3
传递给_initThresholds()
IntersectionObserver.prototype._initThresholds = function(opt_threshold) {
var threshold = opt_threshold || [0];
if (!Array.isArray(threshold)) threshold = [threshold];
return threshold.sort().filter(function(t, i, a) {
console.log(t, i, a);
if (typeof t != 'number' || isNaN(t) || t < 0 || t > 1) {
throw new Error('threshold must be a number between 0 and 1 inclusively');
}
return t !== a[i - 1];
});
};
如果以上代码段在Safari上运行,则返回:
`0.3 – 0 – undefined` in Safari
TypeError: undefined is not an object (evaluating 'a[i - 1]')
在Chrome和Firefox上,它返回:
0.3 0 Array [ 0.3 ]
Array [ 0.3 ]