Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine parent object from reference to a property

var object = {foo: 'bar'};

Does JavaScript have a way to determine that object.foo is a property of object from inside a function to which object.foo is passed? In other words, is it possible to write a func that could do this:

getSource(object.foo) === object
like image 908
ryanve Avatar asked Dec 06 '25 13:12

ryanve


1 Answers

No, there's no back-reference like that in JavaScript. What gets passed into a function is a value -- 5, "foo", an object reference, etc. There's no information on that value that tells you the value came from an object property, much less which object's property.

like image 138
T.J. Crowder Avatar answered Dec 10 '25 08:12

T.J. Crowder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!