Created
January 19, 2018 04:35
-
-
Save seleb/c7f5a25c40742287b34bf9587df0786d to your computer and use it in GitHub Desktop.
Expose getter/setter for private vars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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