Javascript 检查供应商的正确方法,例如webkitRequestAnimationFrame | | mozRequestAnimationFrame

Javascript 检查供应商的正确方法,例如webkitRequestAnimationFrame | | mozRequestAnimationFrame,javascript,Javascript,我从Google()获得了以下代码: 这怎么有效?如果未定义requestAnimationFrame,javascript将在检查moz、webkit或ms之前崩溃 难道不是: var raf = typeof requestAnimationFrame !== 'undefined' ? requestAnimationFrame : typeof mozRequestAnimationFrame !== 'undefined' ? requestAnimationFrame : ty

我从Google()获得了以下代码:

这怎么有效?如果未定义requestAnimationFrame,javascript将在检查moz、webkit或ms之前崩溃

难道不是:

var raf =   
typeof requestAnimationFrame !== 'undefined' ? requestAnimationFrame :
typeof mozRequestAnimationFrame !== 'undefined' ? requestAnimationFrame :
typeof webkitRequestAnimationFrame !== 'undefined' ? requestAnimationFrame :
typeof msRequestAnimationFrame!== 'undefined' ? requestAnimationFrame : null;

我看到的方法是在每个变量前面加前缀
window.
。如果试图访问未定义的变量,而不是对象上未定义的属性,JavaScript将抛出错误

var raf = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;

你在哪里找到这个代码的?它是来自谷歌的API文档,还是只是一个随机链接(你怎么知道它是否可信?@RocketHazmat我用这个链接建立了这个链接,我在IE7上不再出现错误……但我在requestAnimation和window.requestAnimation之间得到了不同的性能结果。它们不相等吗???使用window.requestAnimationFrame,谷歌会扣除“速度性能点”,但不会扣除requestAnimationFrame。我以为他们是一样的。这可能超出了这个问题的范围。谢谢。这些“速度性能点”可能是因为
a
窗口略快。a
,但在您的情况下
a
可能不存在。我在这里就不理它了。
var raf = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;