Detect working CustomEvent constructor

javascript

Solution

The following should work, even on IE6, i've tested it on an old XP machine with IE6.

if (typeof CustomEvent === 'function') {
    ev = new CustomEvent('splat');
}

Problem

I want to test whether the `CustomEvent` constructor is supported. ``` var ev; if (/* CustomEvent constructor supported? */) { ev = new CustomEvent('splat'); } else { ev = document.createEvent('Event'); ev.initEvent('splat'); } this.dispatchEvent(ev); ``` I don't have any machines running IE nearby to test it. Does it throw an error so I can use try/catch, or do I need to do something else? What about older non-IE browsers?

Original source