mootools
Digging into the source code of your favorite JavaScript framework is essential to becoming a {insert framework here} rock star. Digging into other JavaScript frameworks is essential to opening your mind about JavaScript and can give you new ideas to implement improvements in your favorite framework. I was recently looking at the jQuery source code and found that jQuery checks to see if the DOM is ready every 13 milliseconds. MooTools does this same check every 50 milliseconds. Speeding up MooTools' DOMReady check, however, is as easy as updating a periodical's interval.
挖掘最喜欢JavaScript框架的源代码对于成为{insert framework here}摇滚明星至关重要。 深入研究其他JavaScript框架对于打开您JavaScript视野至关重要,并且可以为您提供新的想法,以实现您喜欢的框架中的改进。 我最近在查看jQuery源代码,发现jQuery每隔13毫秒检查一次DOM是否准备就绪。 MooTools每50毫秒执行一次相同的检查。 但是,加快MooTools的DOMReady检查就像更新期刊的间隔一样容易。
MooTools JavaScript (The MooTools JavaScript)
var repeat;
if (Browser.ie){
var temp = document.createElement('div');
repeat = function(){
(Function.stab(function(){
temp.doScroll(); // Technique by Diego Perini
return document.id(temp).inject(document.body).set('html', 'temp').dispose();
})) ? domready() : repeat.delay(50);
};
repeat();
} else if (Browser.safari && Browser.version < 4){
repeat = function(){
(['loaded', 'complete'].contains(document.readyState)) ? domready() : repeat.delay(50);
};
repeat();
} else {
document.addEvent('DOMContentLoaded', domready);
}
The above code is the important piece of the DOMReady utility file. You'll see ".delay(50)" twice in that code block; that's the number we'll update:
上面的代码是DOMReady实用程序文件的重要组成部分。 您将在该代码块中看到两次“ .delay(50)”。 那就是我们要更新的数字:
//....more code
repeat.delay(20);
Voila! Faster DOMReady checks!
瞧! 更快的DOMReady检查!
To my knowledge, there's no science to what that number should be so don't feel as though I'm saying you should modify this number. Just wanted to let you know it was possible!
据我所知,这个数字应该是多少还没有科学依据,所以不要觉得我是在说应该修改这个数字。 只是想让您知道这是可能的!
mootools