天天看點

mootools 擷取類名_MooTools類嗅探器書簽

mootools 擷取類名

I was recently reviewing a few MooTools-driven websites and one of the questions I wrote down was "Which MooTools Core classes do you use and how many classes have you created?" Then I asked myself if there was a way I could figure that out myself. The end result is a JavaScript bookmarklet that finds all of the MooTools classes defined within the Window object.

我最近正在審查一些由MooTools驅動的網站,我寫下的問題之一是“您使用哪個MooTools核心類,并且建立了多少個類?” 然後我問自己是否有辦法解決這個問題。 最終結果是一個JavaScript小書簽,可找到Window對象中定義的所有MooTools類。

MooTools Bookmarklet MooTools書簽

MooTools JavaScript (The MooTools JavaScript)

(function() { 
if(window.MooTools == undefined) return false;
var classes = [];
for(obj in window) {
	try {
		var typo = (window.$type != undefined ? $type(window[obj]) : typeOf(window[obj]));
		if(typo == 'class') {
			classes.push(obj);
		}
	} catch(e) { }
}
classes.sort();
console.log('# Classes: ' + classes.length);
classes.each(function(klass) {
	console.log(klass);
}); })();
           

The key to finding each class is using the $type (< MooTools 1.3) or typeOf (MooTools 1.3) functions. If the result is "class", we've found a class in the given scope. The scope we're searching for is window scope. You can easily change the code snippet to change scope. Checking every scope would be far too taxing so I've stuck to window-level objects.

查找每個類的關鍵是使用$ type(<MooTools 1.3)或typeOf(MooTools 1.3)函數。 如果結果為“ class”,則在給定範圍内找到一個類。 我們正在搜尋的範圍是視窗範圍。 您可以輕松地更改代碼段以更改範圍。 檢查每個範圍都太費力了,是以我堅持使用視窗級對象。

MooTools Bookmarklet MooTools書簽

There you have it. MooTools 1.3 is structured a bit differently than 1.2 so you'll see far fewer classes with 1.3. Just a part of minimizing globals and tightening up this masterful framework!

你有它。 MooTools 1.3的結構與1.2有所不同,是以使用1.3可以看到更少的類。 隻是最小化全局變量和加強這個精巧架構的一部分!

翻譯自: https://davidwalsh.name/mootools-class-bookmarklet

mootools 擷取類名