我在HTML頁面的<head>
部分找到此代碼(collegue使這個,但他不在這裏工作了):理解晦澀的JavaScript代碼
(function(window, PhotoSwipe){
document.addEventListener('DOMContentLoaded', function(){
var options = {},
instance = PhotoSwipe.attach(window.document.querySelectorAll('#Gallery a'), options);
}, false);
}(window, window.Code.PhotoSwipe));
我能夠理解中央部分(從document.addEventListener),我無法理解第一行和最後一行。他們在這裏做什麼?該代碼來自名爲PhotoSwipe的開源圖像庫。任何指針讚賞。
[編輯]
這段代碼一樣:
document.addEventListener('DOMContentLoaded', function(){
var options = {},
instance = window.Code.PhotoSwipe.attach(window.document.querySelectorAll('#Gallery a'), options);
}, false);
?
我發現這是您可以使用該庫下載示例的確切副本。 – Battery 2012-04-18 14:59:33