Ever gotten some output on the console like [Object object]
, with no explanation?
Can't find where it's being logged?
Maybe it comes right before some ludicrous error or crash.
Sometimes you just need a hack.
JavaScript
var ots = Object.prototype.toString;
Object.prototype.toString = function() { try { return JSON.stringify(this); } catch (e) { return ots.apply(this); } };
CoffeeScript
ots = Object::toString
Object::toString = -> try JSON.stringify @ catch then ots.apply @
This will let you actually see the contents of these mysterious [Object object]
s.
Of course, this will screw up any libraries or code that relies on the default behaviour of Object.prototype.toString
.