I was checking this code from html5rocks: http://www.html5rocks.com/static/demos/parallax/demo-1a/scripts/parallax.js
And notice that they use
(function(win, d) {
var $ = d.querySelector.bind(d);
....
var mainBG = $('section#content');
....
})(window, document);
Why they bind the document to the querySelector. Isn't it already scoped to the document?
No, the function is not bound to a specific document (there may be other ones, not just window.document
). Try it without, and you will get an WRONG_THIS_ERR
exception - you will need to apply it on an object that implements the Document
interface.
Also have a look on MDN's introduction to the this
keyword on how the thisVal
("context") of a function call is determined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With