What is Facebook's function __d
facebook, javascript
Solution
As, I have inspected Facebook JavaScript SDK. I believe that it uses Dependency Injection Mechanism. Here are two URLs.
Production: http://connect.facebook.net/en_US/all.js (obfuscated)
Development: http://connect.facebook.net/en_US/all/debug.js (deobfuscated)
If you check debug.js, you can see `require, __d, __t` and many more. `__d` is more like define function from RequireJS (http://requirejs.org/docs/api.html#define)
__d = function(/*string*/ id, /*array<string>*/ deps, factory,
/*number?*/ _special) {/*TC*/__t([id,'string','id'],[deps,'array<string>','deps'],[_special,'number?','_special']);/*/TC*/
Problem
I'm working on a project that (hopefully) involves taking advantage of some of the javascript that's already built into Facebook. But right away I've got a roadblock in that I can't figure out what `__d` is. If you look at the source javascript files, pretty much every command begins with `__d` For example: ``` __d("legacy:live-timer",["LiveTimer"],function(a,b,c,d){a.LiveTimer=b('LiveTimer');},3); ``` But I can't find anywhere in any of the javascript files what `__d` actually does. Shouldn't it have to be defined somewhere for all these other functions to take advantage of it? UPDATE: So let's say there's a site with some javascript like this... ``` function alertSomething(var) { if (var) alert("Here it is: "+var); } if (some condition) alertSomething("something"); ``` Now let's say I had a Chrome Extension and I was able to inject my own Javascript into the page. Couldn't \my Chrome Extension Javascript have something like this... ``` if (some other condition) alertSomething("something else"); ``` Thus I would be taking advantage of some code that exists in the javascript already on the page?