$(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 в своей консоли, я получаю вывод:
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);
}());
Намерение сделать это, чтобы сделать эту функцию первой выполненной в теге скрипта?