Skip to content

Instantly share code, notes, and snippets.

@jameswomack
Last active December 6, 2017 06:06
Show Gist options
  • Select an option

  • Save jameswomack/6258a729b97462322461848cc1f70f2b to your computer and use it in GitHub Desktop.

Select an option

Save jameswomack/6258a729b97462322461848cc1f70f2b to your computer and use it in GitHub Desktop.
Get all non-object-inherited-from values on window
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
}, { })
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