Is it possible to extract an Object out of a Function with JavaScript?
The function I received inside of an Object:
function item(){ let product = { name: name, price: price } }
I want to extract the Object: product out of that function. Caveat: The function may not be changed.
Extracting the Object product
2
Answers
I guess the only way is to eval the function’s body:
If you do can have some tolerance on the changes of the function implementation, you can try the following changes:
Method 1: Return the
product
inside a functionMethod 2: Use Closure
Method 3: Use Global Variable