---
title: "Ext JsonReader        Json元素.getXX/accessor"
author: "side91"
date: "2009-08-16T03:11:51Z"
tags: []
slug: "ext-jsonreader-json-getxx-accessor"
draft: false
lastmod: "2009-08-16T03:12:25Z"
id: 450389
url: "https://side91.iteye.com/blog/450389"
---

```
<html>
<head>
<script>

 

    obj = {'id':'id1','cls':{'name':'name11','type':'type432'}}


    getJsonAccessor = function(){


        var re = /[\[\.]/;
        return function(expr) {

                return(re.test(expr))
                    ? new Function("obj", "return obj." + expr)
                    : function(obj){
                        return obj[expr];
                    };

        };


    }()


</script>
</head>


<script>

...

map["id"]  =  getJsonAccessor("id"))  //返回funtion(obj)..

map["cls.name"]  =  getJsonAccessor("cls.name"))

map["cls.type"]  =  getJsonAccessor("cls.name"))

 

alert(map["id"](obj))      //   obj.getId()       IdAccessor(obj)

 

</script>

 
```