Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
Created July 23, 2010 19:28
Show Gist options
  • Save kara-ryli/487920 to your computer and use it in GitHub Desktop.
Save kara-ryli/487920 to your computer and use it in GitHub Desktop.
More helpful JavaScript Object.toString() implementation
// c.f. http://twitter.com/trek/status/19360844819
Object.prototype.toString = function() {
return "Fuck you, bitches";
};
alert({ foo: 'bar' });
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