function obj2Str(obj){
switch(typeof(obj) ){
case '객체':
var ret = [];
if (obj 인스턴스of 배열){
for (var i = 0, len = obj.length; i < len; i ){
ret.push(obj2Str(obj[i]));
}
return '[' ret.join(',') ']';
}
else if (obj 인스턴스of RegExp){
return obj.toString();
}
else{
for (var a in obj){
ret.push(a ':' obj2Str(obj[a]));
}
return '{' ret.join(',') '}';
}
case 'function':
return 'function() {}';
케이스 '번호':
return obj.toString();
case 'string':
return """ obj.replace(/(\|")/g, "\$1").replace(/n|r|t/g, function(a) { return ("n"==a)?"\n":("r"==a)?"\r":("t"==a)?"\t":"";}) "" ";
case 'boolean':
return obj.toString();
기본값:
return obj.toString();
}
}