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 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”,则在给定范围内找到一个类。 我们正在搜索的范围是窗口范围。 您可以轻松地更改代码段以更改范围。 检查每个范围都太费力了,所以我坚持使用窗口级对象。

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 获取类名

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值