Created
April 25, 2014 14:48
-
-
Save amatiasq/11292163 to your computer and use it in GitHub Desktop.
This file contains 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 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