anyone know how to use Reflection in Node.js/Discord I want to replace
my direct map property call: Userlist.get(uid).Strength
with a more programic one like var DamangeStateName = "Strength" Userlist.get(uid).DamangeStateName
which would get the Strength property like the direct one. The main reason I need reflection is because sometimes the Key attribute is "Agilty" not "Strength" And while my code everwhere else works with the string variable my Map of the player data can't use those same tricks and i need to be able to use reflection os it synergies with the rest of my code
JavaScript, being a prototype-based language where everything is basically just a hashtable of strings to values, neither has nor needs reflection machinery in the sense that Java or C# have.
I think you want something like this:
Userlist.get(uid)[DamangeStateName]
I believe you don't need reflection for your stated problem. You want to be able to handle two keys that mean the same thing.
Extend the target item (object/class) with a method to wrap the logic.
Userlist.get(uid).DamangeStateName
User.prototype.NormalizedDamangeStateName = function() { /* ... */ }
My User
is an assumption. You'll need to identify the correct object by determining what Userlist.get(...)
returns... Regardless, the concept should be sound.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.