![](/img/trans.png)
[英]Is it possible to check whether a function is a javascript function or a developer defined function?
[英]Check whether an object/function is defined (JavaScript, Safari issue)
我想檢查是否可以使用對象/函數,例如window.performance.now()
。 if(typeof window.performance.now != 'undefined')
工作正常,但Safari(5.1.7,Windows)除外,它返回TypeError: 'undefined' is not an object (evaluating 'window.performance.now')
。 為避免混淆: console.log(typeof window.performance.now)
返回相同的錯誤。
因為Safari不支持window.performance
對象本身。 因此,您會更安全地檢查
typeof window.performance !== 'undefined' && typeof window.performance.now !== 'undefined'
更新
第一個檢查是查看window.performance
對象是否存在。 第二項檢查是查看window.performance
對象中的.now()
函數是否可用。
https://developer.mozilla.org/en-US/docs/Web/API/Performance
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.