Last active
June 20, 2016 09:57
-
-
Save AurelioDeRosa/d20b82fb778e2c2819f8ca077c0d9a91 to your computer and use it in GitHub Desktop.
Test if the options parameter of addEventListener() is supported and which options are available
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 getOptionsAvailable() { | |
var optionsAvailable = { | |
capture: false, | |
passive: false, | |
once: false | |
}; | |
try { | |
var eventListenerOptions = {}; | |
Object | |
.keys(optionsAvailable) | |
.forEach(function(option) { | |
Object.defineProperty(eventListenerOptions, option, { | |
get: function() { | |
optionsAvailable[option] = true; | |
} | |
}); | |
}); | |
window.addEventListener('test', null, eventListenerOptions); | |
} catch (ex) { | |
} finally { | |
return optionsAvailable; | |
} | |
} | |
function isOptionsSupported() { | |
return getOptionsAvailable().capture; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment