Skip to content

Instantly share code, notes, and snippets.

@FireNeslo
Last active December 16, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FireNeslo/5501702 to your computer and use it in GitHub Desktop.
Save FireNeslo/5501702 to your computer and use it in GitHub Desktop.
This is just a small function I created to see the structure of an event object in the log i recieved from phonegap. It's great for everyone that hates the "[object Object]" string in their logs.
function stringDebug(sender, method, object) {
var tostring =Object.prototype.toString;
Object.prototype.toString = function(padding) {
padding = padding || 3;
var res = Array(padding-2).join(" ")+"{";
var _self = this;
for(var attr in _self) {
res += '\n' + Array(padding).join(" ") + attr + " : " + ((this[attr] && (padding +2) < 12) ? this[attr].toString(padding +2) : "null");
}
return res+"\n"+Array(padding-2).join(" ")+"}";
}
sender[method]("debug: "+ object);
Object.prototype.toString = tostring;
}
(function example() {
var object = {
you : "see",
even : {
"this" : "rather"
},
complicated : {
object : {
is : "stringable",
loop : object,
"function" : function(param) {
console.log("this is a function");
return param;
}
}
}
};
//alert example
stringDebug(window, "alert", object);
//console log
stringDebug(console, "log", object);
/* Output:
debug: {
you : see
even : {
this : rather
}
complicated : {
object : {
is : stringable
loop : null
function : function (param) {
console.log("this is a function");
return param;
}
}
}
}
*/
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment