Created
August 5, 2019 14:09
-
-
Save galpx/9889e557ac127499cd8dc3942a58500b 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 _isEvent(prop) { | |
if (0 !== prop.indexOf('on')) { | |
return false; | |
} | |
return true; | |
} | |
function _getEvents(obj) { | |
var result = []; | |
for (var prop in obj) { | |
if (_isEvent(prop)) { | |
prop = prop.substr(2); // remove "on" at the beginning | |
result.push(prop); | |
} | |
} | |
return result; | |
} | |
function getEvents() { | |
const result = {}; | |
result['window'] = _getEvents(window, hasOwnProperty); | |
const arr = Object.getOwnPropertyNames(window); | |
for (let i = 0; i < arr.length; i++) { | |
const element = arr[i]; | |
let resultArray = []; | |
try { | |
const obj = window[element]; | |
if (!obj || !obj['prototype']) { | |
continue; | |
} | |
proto = obj['prototype']; | |
resultArray = _getEvents(proto); | |
} catch (err) { | |
// console.error(`failed to get events of %o`, element); | |
} | |
result[element] = resultArray; | |
} | |
return result; | |
} | |
console.log(getEvents()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment