Last active
September 10, 2017 20:21
-
-
Save wizard04wsu/e3192fec332f448893f9 to your computer and use it in GitHub Desktop.
Clones an event object. You can optionally pass new initialization values to override the ones from the cloned event object.
This file contains hidden or 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 cloneEventObj(eventObj, overrides){ | |
var p, eventInit = {}, clone; | |
overrides = overrides || {}; | |
for(p in eventObj){ | |
eventInit[p] = eventObj[p]; | |
} | |
for(p in overrides){ | |
eventInit[p] = overrides[p]; | |
} | |
clone = new eventObj.constructor(eventObj.type, eventInit); | |
//make sure any custom properties get copied to the new event object | |
for(p in eventInit){ | |
try{ | |
clone[p] = eventInit[p]; | |
} | |
catch(e){} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment