Created
April 6, 2018 02:34
-
-
Save netjordanlee/96987e3fd9d60f76a12af12a00e7b738 to your computer and use it in GitHub Desktop.
new Event() for old browsers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Event(name, params) { | |
if(typeof name !== 'string') throw new Error('TypeError'); | |
var _evt; | |
_evt = document.createEvent('Event'); | |
_evt.initEvent(name, true, true); | |
if(typeof params === 'object') | |
for(var p in params) { | |
if(!_evt.hasOwnProperty(p)) { | |
_evt[p] = params[p]; | |
} else { | |
throw new Error('AccessViolation'); | |
} | |
} | |
return _evt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment