4 ms·
"You can write your own basic jQuery by doing this: var $ = document.querySelectorAll; Obviously this won’t cover everything, [...]" wat
by dkyc 12y ago
"You can write your own basic jQuery by doing this:
var $ = document.querySelectorAll;
Obviously this won’t cover everything, [...]"
wat
- moron4hire 12y agoIt's not even right for what the article author is trying to do. Or in other words, s/he just broke their own rule #1: understand "this". "document.querySelectorAll" must be called on the document object, and reassigning it to a variable like this will make it be called in whatever function scope it's currently in. To even get this to call correctly, it needs to be "var $ = document.querySelectorAll.bind(document);"
- TheZenPsycho 12y ago>> "document.querySelectorAll" must be called on the document object, and reassigning it to a variable like this will make it be called with "this" assigned to the global object, or "undefined" if you're using "use strict" fixed.