Last active
December 6, 2017 06:06
-
-
Save jameswomack/6258a729b97462322461848cc1f70f2b to your computer and use it in GitHub Desktop.
Get all non-object-inherited-from values on window
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
| window.__previousTypeOfBucketTable__ = window.__typeOfBucketTable__ ? window.__typeOfBucketTable__ : { }; Reflect.ownKeys(window).filter(aWindowOwnedKey => { | |
| return !({}).constructor[Symbol.hasInstance](window[aWindowOwnedKey]) | |
| }).reduce((typeOfBucketTable, aWindowOwnedKeyForNonObjects) => { | |
| const typeOfThisWIndowOwnedKey = typeof window[aWindowOwnedKeyForNonObjects] | |
| typeOfBucketTable[typeOfThisWIndowOwnedKey] || (typeOfBucketTable[typeOfThisWIndowOwnedKey] = { length: 0 }) | |
| typeOfThisWIndowOwnedKey === 'object' && typeOfBucketTable[typeOfThisWIndowOwnedKey].length === 0 && (typeOfBucketTable[typeOfThisWIndowOwnedKey].__everyObjectIsNull__ = true) | |
| typeOfBucketTable[typeOfThisWIndowOwnedKey][aWindowOwnedKeyForNonObjects] = window[aWindowOwnedKeyForNonObjects] | |
| typeOfBucketTable[typeOfThisWIndowOwnedKey].length = typeOfBucketTable[typeOfThisWIndowOwnedKey].length + 1 | |
| typeOfThisWIndowOwnedKey === 'object' && window[aWindowOwnedKeyForNonObjects] != null && (typeOfBucketTable[typeOfThisWIndowOwnedKey].__everyObjectIsNull__ = false) | |
| window.__typeOfBucketTable__ || (window.__typeOfBucketTable__ = typeOfBucketTable) | |
| return typeOfBucketTable | |
| }, { }) |
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
| Reflect.ownKeys(window).filter(aWindowOwnedKey => { | |
| return Reflect.getOwnPropertyDescriptor(window, aWindowOwnedKey).enumerable | |
| /* The above could be `return window.propertyIsEnumerable(aWindowOwnedKey)`... | |
| ~~~ | |
| It's terrible, BTW, that `Reflect` has so many methods that look like they operate on | |
| arguments but operate on itself. Not only that, but they don't throw errors or log | |
| warnings when you call them as if they were tartgeting arguments. | |
| ~~~ | |
| */ | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment