Skip to content

Instantly share code, notes, and snippets.

Embed
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 - $$('img.dog')
var $$ = document.querySelectorAll.bind(document);
// Credit: https://twitter.com/wesbos/status/608341616173182977
@jorgevilaca82

This comment has been minimized.

Copy link

@jorgevilaca82 jorgevilaca82 commented Jun 15, 2015

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

var $ = document.querySelector;
@eduard-ishmukhametov

This comment has been minimized.

Copy link

@eduard-ishmukhametov eduard-ishmukhametov commented Jun 15, 2015

jQuery analogy may be misleading

@AllThingsSmitty

This comment has been minimized.

Copy link
Owner Author

@AllThingsSmitty AllThingsSmitty commented Jul 19, 2015

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

@wesbos

This comment has been minimized.

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