文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>js简易反射类

js简易反射类

时间:2008-11-26  来源:flynetcn

<script type="text/javascript">
//反射类
function Reflector()
{
    Reflector.getType=function(obj)
    {
        if (obj == null) {
            return null;
        } else if (obj instanceof Object) {
            return obj.constructor;
        } else if (obj.tagName != null) {
            return obj.tagName;
        } else {
            return typeof(obj);
        }
    }
    Reflector.getAttributes=function(obj)
    {
        var methods = new Array();
        for (key in obj) {
            methods.push(new Type(obj[key], this.getType(obj[key]), key));
        }
        return methods;
    }
    Reflector.getAttributeNames=function(obj)
    {
        var methods = new Array();
        for (key in obj) {
            methods.push(key);
        }
        return methods;
    }
}
function Type(entity, type, name)
{
    this.Entity = entity;
    this.Type = type;
    this.Name = name;
}


//使用示例
var oRef = new Reflector();
var arrRef = Reflector.getAttributes(obj);
var str = '';
for(var i=0;i<arrRef.length;i++)
{
    str += arrRef[i].Type+" : "+arrRef[i].Name+"\n";
}
alert(str);
</script>

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载