I came across the following script, and do not understand the first line. It apparently either returns JSON.stringify or an anonymous function. Is it best to do it this way, or using the traditional the function printObj(obj)
? Also, where does JSON get defined? Thanks
var printObj = typeof JSON != "undefined" ? JSON.stringify : function(obj) {
var arr = [];
$.each(obj, function(key, val) {
var next = key + ": ";
next += $.isPlainObject(val) ? printObj(val) : val;
arr.push( next );
});
return "{ " + arr.join(", ") + " }";
};
$("#log").append( printObj(object1) );