$(document).ready(function(){
console.log('a');
});
window.fbAsyncInit = function() {
FB.init({appId: '{/literal}{$fbAppId}{literal}',
status: true,
cookie: true,
xfbml: true});
FB.Event.subscribe('edge.create', function(response) {
// Do something, e.g. track the click on the "Like" button here
if(!liked)
{
{/literal}$.get('http://{$rooturl}/promotions/likecheck.php?CID={$CID}&ctype={$campaignTable}');{literal}
liked=true;
}
});
};
(function() {
console.log('b');
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
我注意到,当我运行这个JavaScript在我的控制台我得到的输出:的Javascript事件语法问题
b
a
我想知道这是什么意思包裹在括号中的函数在这里的JavaScript:
(function() {
console.log('b');
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
这样做的目的是使这个功能第一次执行脚本标记?