Skip to content

Instantly share code, notes, and snippets.

@DigiTec
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save DigiTec/94e34500420b2fb5744a to your computer and use it in GitHub Desktop.

Select an option

Save DigiTec/94e34500420b2fb5744a to your computer and use it in GitHub Desktop.
This enumerates the window to find types that inherit from EventTarget.
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