2014-01-31 47 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(); 
}); 

最好的一般性的建议,我可以给的“研究一些模式” ,如显示模块模式。