Skip to content

Instantly share code, notes, and snippets.

@rndme
Created October 31, 2025 01:40
Show Gist options
  • Select an option

  • Save rndme/6deb3b0ffea195a365a623a4dbc3e00a to your computer and use it in GitHub Desktop.

Select an option

Save rndme/6deb3b0ffea195a365a623a4dbc3e00a to your computer and use it in GitHub Desktop.
function toSource(o){ // quick and dirty object literals w/ methods. good for refactoring.
var old = Function.prototype.toJSON;
Function.prototype.toJSON = function () {
return "#>"+this.toString()+"<#";
};
var s = JSON.stringify(o, null, "\t");
s=s.replace(/"#>([\w\W]+?)<#"/g, (a,b)=>eval('"'+b+'"'));
Function.prototype.toJSON = old;
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment