Last active
December 18, 2015 14:09
-
-
Save mutoo/5795381 to your computer and use it in GitHub Desktop.
a simple way to avoid memory locator detecting a number's address;
This file contains hidden or 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 addProperty = function(obj, property, value) { | |
| var salt = Math.random(), saltValue; | |
| var saltGetter = function() { | |
| return saltValue * salt; | |
| }; | |
| var saltSetter = function(value) { | |
| saltValue = value / salt; | |
| }; | |
| saltSetter(value); | |
| Object.defineProperty(obj, property, { | |
| get: saltGetter, | |
| set: saltSetter | |
| }); | |
| }; | |
| var Hero = function() { | |
| addProperty(this, "hp", 50); | |
| addProperty(this, "mp", 50); | |
| }; | |
| var player = new Hero(); | |
| console.log(player.hp); // 50 | |
| console.log(player.mp); // 50 | |
| player.hp = 100; | |
| player.mp = 75; | |
| console.log(player.hp); // 100 | |
| console.log(player.mp); // 75 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment