8 окт. 2011 г.

JS: debug object with alertObject

Great function to debug js.
function alertObject(obj,comment) {
  var str = (comment)? comment+"\n":'{';
  for(var el in obj) {
    var value = obj[el];
    if ( typeof value == "function" ) {
      value = "[<function>]";
    }
    str += el + " : "+ value +" , ";
  }
  str +=" }"
  alert(str);
}
P.S. Was great few years ago. Now using console.log is much better. But great for a debuggin' in old browsers.