2014-01-31 49 views
-1

我正在研究jquery並對其進行自定義。當我通過瀏覽器查看源代碼來檢查stackoverflow.com的源代碼時。我發現這一點:
jquery如何設置jquery DOM名稱

StackExchange.ready(function() { 
     StackExchange.using("postValidation", function() { 
      StackExchange.postValidation.initOnBlurAndSubmit($('#post-form'), 2, 'answer'); 
     }); 

寫StackExchange.ready和像StackExchange.question.init其功能,StackExchange.realtime.subscribeToQuestion等

請怎樣幫助我

+0

你可以在這裏找到用於StackExchange的JS開發工具 - > Sources - > cdn.sstatic.net - > Js' – Anton

回答

0

喜歡的東西 -

var yourCustomName = $(document);

繼續 - yourCustomName.ready(function() {


#1定製準備方法 -

StackExchange.ready=function(d){StackExchange.initialized.done(d)}; 
+0

但是沒有StackExchange = $(document);在我學習的StackExchange網站 – shailendra

0

StackExchange是他們已經創建包括功能

StackExchange {init: function, debug: Object, initialized: Object, ready: function, using: function…} 
MarkdownEditor: function (a){var c=a.postfix||"";(j=StackExchange.options.site.isMetaStackOverflow||StackExchange.options.site.isChildMeta)&&(D=StackExchange.options.site.parentUrl|| 
anonymous: Object 
captcha: Object 
cardiologist: Object 
chatAd: Object 
comments: Object 
debug: Object 
editor: Object 
gps: Object 
helpers: Object 
ifUsing: function (g,h,d){if("undefined"!==typeof d){if(c["u_"+d])return;c["u_"+d]=!0}StackExchange[g]?h():((d=a[g])||(d=a[g]=[]),d.push(h))} 
imageUploader: Object 
init: function (j){StackExchange.options=j;j.serverTimeOffsetSec=j.serverTime-(new Date).getTime()/1E3;e(j.site.name);$.ajaxSetup({cache:!1});StackExchange.init.createJqueryExtensions(); 
initialized: Object 
inlineEditing: Object 
inlineTagEditing: Object 
loadJsFile: function (a){return n(k()+a)} 
loggedIn: Object 
navPrevention: Object 
newsletterAd: Object 
notify: Object 
openid: Object 
options: Object 
postValidation: Object 
prettify: Object 
question: Object 
ready: function (d){StackExchange.initialized.done(d)} 

要查看StackExchange對象只是在控制檯鍵入StackExchange的對象。你可以找到stackexchange這裏

Developer tools -> Sources -> cdn.sstatic.net -> Js 

的代碼來寫這樣的功能,你可以做

var StackExchange = { 
    init: { 
     questions: function() { 
      console.log("init") 
     } 
    }, 
    ready: function() { 
     console.log("init") 
    }, 
    debug: function() { 
     console.log("init") 
    } 
} 
+0

請問你能告訴我他們在哪裏寫的嗎?在js文件或其他地方? – shailendra

+0

@shailendra他們寫在這裏'Developer tools - > Sources - > cdn.sstatic.net - > Js'這個目錄下的所有文件 – Anton

+0

非常感謝 - 很棒! – shailendra

0
var Question = function() { 
    this.ask = function() { 
     // .... 
    }; 
}; 
window.StackExchange = (function() { 
    var question = new Question(); 
    return { 
     // Add more here to your liking 
     question: question, 
     ready: $(document).ready 
    }; 
}()); 

StackExchange.ready(function() { 
    question.ask(); 
}); 

最好的一般性的建議,我可以給的「研究一些模式」 ,如顯示模塊模式。