Skip to content

Instantly share code, notes, and snippets.

@zachvictor
Last active August 19, 2020 09:06
Show Gist options
  • Save zachvictor/46ea03a20e839017db6f75bc63e6f0c3 to your computer and use it in GitHub Desktop.
Save zachvictor/46ea03a20e839017db6f75bc63e6f0c3 to your computer and use it in GitHub Desktop.
Alias querySelector and querySelectorAll (for console debugging, etc.)
Object.getOwnPropertyNames(window).filter(name => name.match(/^HTML[a-zA-Z]*Element$/)).forEach(h => {
[{abbr: 'qs', name: 'querySelector'}, {abbr: 'qsa', name: 'querySelectorAll'}].forEach(fn => {
try {
window[h]['prototype'][fn.abbr] = window[h]['prototype'][fn.name]
console.log(`${h}: added alias ${fn.abbr} for ${fn.name} method.`)
} catch (e) {
console.log(`${h} has no ${fn.name} method.`, e.message)
}
})
})
@zachvictor
Copy link
Author

hey, as long as it's in the console, and you wear a mask, it's totally ok to add functions to foundational prototypes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment