Last active
August 19, 2020 09:06
-
-
Save zachvictor/46ea03a20e839017db6f75bc63e6f0c3 to your computer and use it in GitHub Desktop.
Alias querySelector and querySelectorAll (for console debugging, etc.)
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
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) | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey, as long as it's in the console, and you wear a mask, it's totally ok to add functions to foundational prototypes