Last active
December 16, 2015 21:39
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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