Skip to content

Instantly share code, notes, and snippets.

@seleb
Created January 19, 2018 04:35
Show Gist options
  • Save seleb/c7f5a25c40742287b34bf9587df0786d to your computer and use it in GitHub Desktop.
Save seleb/c7f5a25c40742287b34bf9587df0786d to your computer and use it in GitHub Desktop.
Expose getter/setter for private vars
var expose = function (target) {
var code = target.toString();
code = code.substring(0, code.lastIndexOf("}"));
code += "this.get = function(name) {return eval(name);};";
code += "this.set = function(name, value) {eval(name+'=value');};";
return eval("[" + code + "}]")[0];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment