What is Facebook's function __d

后端 未结 3 1591
野趣味
野趣味 2021-01-20 12:02

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 t

相关标签:
3条回答
  • 2021-01-20 12:32

    The function __d is API for RequireJS used to Define a Module.

    Example:

    __d('Example', [], function a(b, c, d, e, f, g, h) {
     'use strict';
      if (c.__markCompiled) c.__markCompiled();
      f.exports = {
          a: "Hello World"
          };
     }, null);
    

    Call:

    require('Example');
    

    Output:

      Object {a: "Hello World"}
    
    0 讨论(0)
  • 2021-01-20 12:44

    I found the definition of __d on line 20 of 1LWPxIBQ4v0.js. No idea if the file is named the same for everyone. Search for "a.__d=function(s,t,u,v)" (a is the global object, i.e. window, effectively making __d a global function). Good luck with that de-minification though...

    0 讨论(0)
  • 2021-01-20 12:48

    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*/
    
    0 讨论(0)
提交回复
热议问题