Below is a more generic solution I just wrote, for anyone to use as
they wish, if they wish. Be careful with large/complex objects as
recursion is used:
/**
* This function will iterate through an object and turn values of
it's fields
* that are strings into function call (or whatever else) using
eval(). The purpose at the time
* was to workoaround JSON limitation of not allowing function call
per its spec.
* i.e. [{"header": "Price", "width": 20, "sortable": "true",
"renderer": "Ext.util.Format.usMoney", "dataIndex": "price"}]
* the Ext.util.Format.usMoney is a function, but JSON wraps it into
quotes.
* @param {Object} propertyName The name of the property/field whose
values we
* are about to eval().
* @param {String} objRef The object to be searched
*/
function functionMaker(propertyName, objRef){
var x;
//if we are dealing with an array, recursively iterate
if(objRef instanceof Array){
for(i=0; i<objRef.length; i++){
functionMaker(propertyName, objRef[i])
}
}
for(x in objRef){
if((x != undefined) && (x == propertyName)){
objRef[x] = eval(objRef[x]); //fixed ya!
} else if(objRef[x] instanceof Array){ //if we are dealing
with an array, recursively iterate
for(i=0; i<objRef[x].length; i++){
functionMaker(propertyName, objRef[x][i])