Skip to content

Instantly share code, notes, and snippets.

@getify
Created January 25, 2017 23:31
Show Gist options
  • Select an option

  • Save getify/d15bcb82f96b971d47e4d971587f5c7d to your computer and use it in GitHub Desktop.

Select an option

Save getify/d15bcb82f96b971d47e4d971587f5c7d to your computer and use it in GitHub Desktop.
Make JavaScript Great Again
Object.defineProperty(Object.prototype,Symbol.toStringTag,{
get() {
return JSON.stringify(this);
},
set(v) {
Object.defineProperty(Object.prototype,Symbol.toStringTag,{
value: v,
enumerable: false,
writable: true,
configurable: true
});
},
enumerable: false,
configurable: true
});
({ a: 2, b: 3 }).toString(); // [object {"a":2,"b":3}]
Object.prototype.toStringTag = "cool";
({ a:2, b: 3 }).toString(); // [object cool]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment