Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1179293
  • 博文数量: 252
  • 博客积分: 5421
  • 博客等级: 大校
  • 技术积分: 2418
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-17 12:59
文章分类

全部博文(252)

文章存档

2017年(3)

2016年(18)

2015年(31)

2014年(18)

2013年(7)

2012年(8)

2011年(12)

2010年(30)

2009年(32)

2008年(57)

2007年(36)

分类: 系统运维

2008-11-26 00:34:37

<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>

阅读(954) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~