Skip to content

Instantly share code, notes, and snippets.

@AurelioDeRosa
Last active June 20, 2016 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AurelioDeRosa/d20b82fb778e2c2819f8ca077c0d9a91 to your computer and use it in GitHub Desktop.
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
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