Skip to content

Instantly share code, notes, and snippets.

@git2358
Forked from netjordanlee/event.js
Created April 11, 2018 23:14
Show Gist options
  • Save git2358/77b837cc65c1e7000cbe5c5e75a64381 to your computer and use it in GitHub Desktop.
Save git2358/77b837cc65c1e7000cbe5c5e75a64381 to your computer and use it in GitHub Desktop.
new Event() for old browsers
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