var o = {};
(function(x){x=null})(o); //o is NOT null after this statement
(function(x){x.foo = "foo"; x.bar = "bar";})(o) //o has properties foo and bar after this statement
what is going on when passing object o into the function? the first function makes it seem o did not get passed; the second function makes it seem that o get passed
Line 1: An object is created. A reference to it is passed to o.
Line 2: A function is called. A reference to the object is passed as an argument. The reference (in x) is then overwritten with null (without touching the object itself or the reference to it still assigned to o).
Line 3: A function is called. A reference to the object is passed as an argument. A foo and bar property are added to the object and assigned values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With