最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is Facebook's function __d - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Feb 14, 2013 at 21:29 Rob W 349k87 gold badges807 silver badges682 bronze badges asked Feb 14, 2013 at 17:56 rgbflawedrgbflawed 2,1371 gold badge23 silver badges28 bronze badges 6
  • This is the result of a JavaScript minifier. Why is it important to you what __d does? It seems like it's an internal function that you're not supposed to use. – gen_Eric Commented Feb 14, 2013 at 17:59
  • Because if I want to take advantage of a certain line of code, I need to know what it does. I realize it's something that's been minified, but it still has to be defined somewhere. I thought there was no 'internal' when it came to javascript. I should expect to still see something that says function __d somewhere. – rgbflawed Commented Feb 14, 2013 at 18:01
  • What do you mean by "take advantage of"? This function is not for you to use. And, JavaScript does have private (what I meant by "internal") functions. – gen_Eric Commented Feb 14, 2013 at 18:08
  • 1 @StevenJenkins I found the definition of __d on line 20 of 1LWPxIBQ4v0.js. No idea if the file is named the same for you. Look for a.__d=function(s,t,u,v). – matts Commented Feb 14, 2013 at 18:14
  • @matts This is it! Thanks man! If you want to submit this as an answer, I'd approve it. – rgbflawed Commented Feb 14, 2013 at 18:16
 |  Show 1 more comment

3 Answers 3

Reset to default 15

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*/

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"}

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)

  1. 暂无评论