Let's say I want to detect support for notifications (http://notifications.spec.whatwg.org/) in a JavaScript library.
I can use window.Notification !== undefined
. But what if the users of the library (or another library) also have some kind of global Notification
object defined for completely different purpose?
On the other hand, what if the other library is a polyfill? Then their Notification
object is acceptable. Should I test for all methods in addition to testing for the global object?
Update:
I have noticed an interesting thing in one notifications polyfill:
ret[toString] = function() {
return 'function Notification() { [native code] }';
};
How reliable is relying on something like that to detect whether it is a native/polyfill object?