Last active
August 29, 2015 14:07
-
-
Save DigiTec/94e34500420b2fb5744a to your computer and use it in GitHub Desktop.
This enumerates the window to find types that inherit from EventTarget.
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
| var eventTargetObjects = Object.getOwnPropertyNames(window).filter(function prop(name) { | |
| // This block of code identifies constructors with high confidence using casing, enumerability and prototype property presence | |
| return (name[0] === name[0].toUpperCase() && !this.propertyIsEnumerable(name) && this[name].prototype !== undefined); | |
| }, window).filter(function prop(name) { | |
| // This block of code determines if a constructor is like an EventTarget | |
| var currentPrototype = this[name].prototype; | |
| while (currentPrototype !== null) { | |
| if (currentPrototype === EventTarget.prototype) { | |
| return true; | |
| } | |
| currentPrototype = Object.getPrototypeOf(currentPrototype); | |
| } | |
| return false; | |
| }, window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment