0

Consider something like this.

const myFunc = (x) => x.Property1;
let obj = {
 Property1: "value1",
 Property2: "value2"
};

console.log(myFunc(obj)); // output: value1

I need something like this:

console.log(whatINeed(myFunc, obj)) // output: **Property1**

Is it possible to achieve this requirements ?!

what will be the body of "whatINeed" function ?

Ehsan
  • 1,093
  • 1
  • 12
  • 21

1 Answers1

4

If you run myFunc.toString(), it will give you "(x) => x.Property1". You can then write a parser for that, shouldn't be too hard. It will be hard if you want full-feature like C#.

vothaison
  • 1,646
  • 15
  • 15