我最近一直在看一些網站,看看他們是如何構建他們的jQuery,看着Forrst.com他們似乎有一個非常獨特的使用方式。關於init的jQuery問題
以下是他們網站上的一些代碼片段。
Forrst = {
showingTopClicker: false,
currentUserID: -1,
formKey: "",
init: function() {
$(document).ready(function() {
Forrst.formKey = $("meta[name=forrst-form-key]").attr("content");
Forrst.currentUserID = $("meta[name=forrst-userid]").attr("content");
Forrst.applyLibs();
Stream.init();
$("#promo-excerpt").jTruncate({
length: 95
});
$(".notice-bar a.close").click(function() {
return Forrst.hideNoticeBar()
});
PostForm.init();
People.init();
Comments.init();
Stream = {
isLoading: false,
streamPath: "",
pageBy: "after",
afterID: false,
page: 1,
extraParams: {},
init: function() {
if ($("#stream").length == 0) {
return
}
Stream.redirectFromHash();
$(".post-toggle > a").live("click", function() {
$(this).parent().parent().children(".post").toggle("fast");
$(this).parent().hide();
return false
});
$(window).scroll(function() {
if (($(document).height() - $(window).height()) - $(window).scrollTop() <= 300) {
Stream.loadMore()
}
})
},
redirectFromHash: function() {
if (window.location.hash != null && window.location.hash != "" && window.location.hash.match(/^#?after:/i)) {
var b = window.location.pathname.split("/");
var c = "";
Forrst.init();
任何人都可以解釋這裏發生了什麼,以及以這種方式構建代碼的優點是什麼?謝謝