Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript functions - pulling more than what's been given

This is pure curiosity. Let's write an object:

 var display = { res1:{ w:640, h:480 }, res2:{ w:320, h:240 }, nores:{} };

Now from this object, we're sending the nores property to a function. Since nores is an object, whatever we change in somefunction is going to be seen later in display.nores:

 somefunction(display.nores);

Now here's the question. Does somefunction() has any form of access to display's other properties (res1 / res2) given that display is defined inside a closure and somefunction() was defined outside of that closure? I mean can it reference the whole display object just from its nores property that was passed as an argument?

like image 544
Silviu-Marian Avatar asked Jan 28 '26 02:01

Silviu-Marian


1 Answers

Does somefunction() has any form of access to display's other properties (res1 / res2) given that display is defined inside a closure and somefunction() was defined outside of that closure?

No

I mean can it reference the whole display object just from its nores property that was passed as an argument?

There is no reverse relationship between the properties of an object and their values. The only way to find them would be to have access to the object and then to loop over it until you find a match.

like image 57
Quentin Avatar answered Jan 29 '26 15:01

Quentin