Created
July 23, 2010 19:28
-
-
Save kara-ryli/487920 to your computer and use it in GitHub Desktop.
More helpful JavaScript Object.toString() implementation
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
// c.f. http://twitter.com/trek/status/19360844819 | |
Object.prototype.toString = function() { | |
return "Fuck you, bitches"; | |
}; | |
alert({ foo: 'bar' }); |
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
Object.prototype.toString = function() { | |
var i, m, className, props = []; | |
for (i in this) { | |
if (this.hasOwnProperty(i)) { | |
props.push('"' + i + '": ' + this[i]); | |
} | |
} | |
m = this.constructor.toString().match(/^function ([^\(]*)/); | |
return '<#' + (m ? m[1] : 'Object') + ':{ ' + props.join(',') +' }>'; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment