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