Skip to content

Instantly share code, notes, and snippets.

@amatiasq
Created April 25, 2014 14:48
Show Gist options
  • Save amatiasq/11292163 to your computer and use it in GitHub Desktop.
Save amatiasq/11292163 to your computer and use it in GitHub Desktop.
function listenAll(target) {
var protos = [],
proto = target;
while (proto) {
protos.push(proto);
proto = Object.getPrototypeOf(proto)
}
protos
.reduce(function(props, proto) {
return props.concat(Object.keys(proto))
}, [])
.sort()
.filter(function(a) {
return a.toLowerCase().indexOf('on') === 0
})
.map(function(a) {
return a.substr(2)
})
.forEach(function(a) {
target.addEventListener(a, console.log.bind(console, a));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment