0

Facebook 開発者サイトから取得したこのコード ブロックの構文の一部がわかりません。最初の変数「js」と「id」は何らかの方法でバインドされていますか? 最初の if ステートメントで正確に返されるのは何ですか?

     (function(d){
       var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
       js = d.createElement('script'); js.id = id; js.async = true;
       js.src = "//connect.facebook.net/en_US/all.js";
       d.getElementsByTagName('head')[0].appendChild(js);
     }(document));

これはページへのリンクです: http://developers.facebook.com/docs/guides/web/#personalization

4

2 に答える 2

1

「バウンド」とはどういう意味ですか?

それらは関数ローカルです。js3行目と4行目に設定されている変数で、idすぐに文字列に設定されます。

d関数自体は、関数内に設定された状態で、定義の直後に実行されdocumentます。

最初の(そして唯一の明示的な)returnステートメントでは何も返されません。そして、これが唯一のコードである場合、戻り値をキャプチャするものがないため、戻り値は無意味になります。

于 2012-04-30T14:56:37.317 に答える
0

ここには何もありません。盗まれた空白だけです:)

(function(d){
    var js,    // variable (empty)
        id = 'facebook-jssdk';    // variable with string 'facebook-jssdk'

    if (d.getElementById(id)) {    // is there an element with id 'facebook-jssdk'
        return;    // yes, so we have nothing to do and get out of here
    }

    js = d.createElement('script');    // create 'script' element
    js.id = id;    // assign id 'facebook-jssdk'
    js.async = true;    // load in "background" (if supported)
    js.src = "//connect.facebook.net/en_US/all.js";    // set source (with the appropriate protocol; https if called via https, http otherwise)
    d.getElementByTagNam('head')[0].appendChild(js);    // append to first head element on page
}(document))    // immediately call the anonymous function and hand in the 'document'
于 2012-04-30T17:21:25.600 に答える