Last active
August 20, 2022 13:32
-
-
Save AllThingsSmitty/f9029e6236a7c2a03203 to your computer and use it in GitHub Desktop.
Use querySelector with .bind() as a shortcut to familiar function names
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
// returns first element selected - $('input[name="food"]') | |
var $ = document.querySelector.bind(document); | |
// return array of selected elements - $$('img.dog') | |
var $$ = document.querySelectorAll.bind(document); | |
// Credit: https://twitter.com/wesbos/status/608341616173182977 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why binding? why not just pass the function reference? Like this: