Dojo学习11 dojo类属性查看工具

11. dojo类属性查看工具
有的时候查询一个类的方法,属性比较费事,还得看源代码,而且,有的是继承类,需要看不止一个源代码。今天我写了一个dojo的属性查看器,能够方便的查看一个类的所有属性和方法。
用的时候注意和dojo.js的相对路径:
js
 |-dojo
 |   |-dojo.js
 |-dijit
 |- ....
my
 |-showDetail.htm
 
==================showDetail.htm======================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Button Widget Dojo Tests</title>
<style type="text/css">
 @import "../js/dojo/resources/dojo.css";
 @import "../js/dijit/themes/tundra/tundra.css";
</style> 
<script type="text/javascript"
 djConfig="parseOnLoad: true, isDebug: true"
 src="../js/dojo/dojo.js"></script>
<script type="text/javascript">
/*
 author:amushen
 date:200707
 email:[email protected]
*/
 dojo.require("dojo.parser");
var log=console.log;
function val2type(/*Object*/ value){
  if(dojo.isString(value)){ return "string"; }
  if(typeof value == "number"){ return "number"; }
  if(typeof value == "boolean"){ return "boolean"; }
  if(dojo.isFunction(value)){ return "function"; }
  if(dojo.isArray(value)){ return "array"; } // typeof [] == "object"
  if(value instanceof Date) { return "date"; } // assume timestamp
  if(value instanceof dojo._Url){ return "url"; }
  return "object";
 }

function showDetail(){
 console.clear();
 var className=form1.dojotype_.value;
 var isAll;
 {
  if(form1.RadioGroup1[0].checked)isAll=1;
  else isAll=0;
 }
 if(className.length<1)return;
 try{
 dojo.require(className);
 }catch(e){log("Could not load class '" + className +
     "'. Did you spell the name correctly and use a full path, like 'dijit.form.Button'?");return;}
 var cls = dojo.getObject(className);  
 var proto = cls.prototype;
 var params={};
 var cnt=0;

 log("---=== "+className+" ===---");
 for(var name in proto){
  var defVal = proto[name];  
   if(!isAll&&name.charAt(0)=="_"){ continue; }
   log((++cnt)+" -->> "+name+":"+val2type(defVal));
  }
 log("===end of class: "+className+" ===");
 
}
</script>
</head>
<body class="tundra">
<h1>dojo的任何一个类的属性查询器,在文本框内输入类的全称即可,注意大小写</h1><br>
<form name="form1" onSubmit="showDetail();return false;">
className:<input type="text" size="20" name="dojotype_" value="/dijit.form.Button" /><br>
<p>
  <label>
  <input type="radio" name="RadioGroup1" value="0">
    全部属性</label>
  <br>
  <label>
  <input type="radio" name="RadioGroup1" value="1" checked>
    公共属性</label>
  <br>
</p>
<input type="button" value="查询" onclick="showDetail()" />
</form><br>
<br>
</body>
</html>

你可能感兴趣的:(Dojo学习11 dojo类属性查看工具)