javascript - Understanding some jsfiddle code in looking at - need some explanation -
i'm looking @ code in jsfiddle around firebase authentication
http://jsfiddle.net/firebase/a221m6pb/
but there things im not quite getting looking @ code... function declared @ top
(function (jquery, firebase, path) {
is way of injecting services/libraries jsfiddle?, havent seen example before...also can tell me path in method signature is?... understand used in routing in example im not sure is.. sort of routing framework... apologies if these obvious question, im relatively new playing around jsfiddle + javascript
way down @ bottom can see whats passed parameters.
(window.jquery, window.firebase, window.path)
it's way of making sure variables reference correct objects in desired scope.
and yes, path
routing. around line ~300, you'll see.
there's lots of comments & annotation, should keep reading script.
side note, has nothing in particular jsfiddle. jsfiddle code editor platform, there many, many it: jsbin, codepen, webdevout, plunker - list goes on.
expanding on answer, in regards comments. if click external resources tab on left side, list of scripts , resources have been added environment. of time, scripts create kind of namespace object on global object - in browser global object window
- end window.jquery
, window.path
, window.firebase
, , on. since every scope has access global scope, you'll see jquery
(or $
) used freely inside functions, since it's assumed global reference won't change - if does? if library or tool writes on namespace in middle of program? break references!
the whole point of function pass window.jquery
parameter called jquery
make sure in scope of function jquery
means think should, since global reference (window.jquery
) might written on other library unknowingly. don't care namespace has or might written on now, because you've established reference original object.
the path
object provided library: pathjs
some further reading:
Comments
Post a Comment