| ▲ | no_wizard 2 days ago | ||||||||||||||||
>You can only just barely figure out what is in an object There's a couple really well documented and understood ways of doing this in the language. I'm not sure what you're specifically referencing without more information. >I wouldn't so much as call what JS does "reflection" any more than "making objects out of poorly implemented hashmaps." Is this anymore different than .NET deriving everything from a base `System.Object`[0] type? Also, what is missing in JS reflection wise that you can't do that would make sense for its environment? (namely, this excludes compile time reflection stuff I know .NET can do, it wouldn't make sense for a scripting language as it currently is) [0]: https://learn.microsoft.com/en-us/dotnet/api/system.object?v... | |||||||||||||||||
| ▲ | moron4hire 2 days ago | parent [-] | ||||||||||||||||
In JavaScript, one can tell if an object has a method by iterating over the object keys and seeing if the value is `instanceof Function`. But that actually tells you very little. You might be able to tell that it takes a certain number of parameters, if you are running on a system that implements Function.prototype.length. But you will have no way of telling what the arguments to those parameters should be, or even what they were even named. There's no way to tell if the function is a method that needs to be `.call()`ed with a value for "this", or if it's just a function that happens to live in an object literal, or if it's actually a class constructor that must be called with `new`! And there is certainly no way to tell whether the function returns a value, say nothing about the type of value it returns. With .NET reflection, I can do ask those things I lament missing in JS, and guarantee the type safeness of it. | |||||||||||||||||
| |||||||||||||||||