Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use querySelector with .bind() as a shortcut to familiar function names
// returns first element selected - $('input[name="food"]')
var $ = document.querySelector.bind(document);
// return array of selected elements - $$('')
var $$ = document.querySelectorAll.bind(document);
// Credit:
Copy link

jorgevilaca82 commented Jun 15, 2015

Why binding? why not just pass the function reference? Like this:

var $ = document.querySelector;

Copy link

eduard-ishmukhametov commented Jun 15, 2015

jQuery analogy may be misleading

Copy link

AllThingsSmitty commented Jul 19, 2015

bling.js may have the best answer for this use case.

Copy link

wesbos commented Aug 25, 2015

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