?> I want to understand why we can change the passed object inside mutate by 
lets say adding more properties to it but not this way where I am redefining it 
as a function object.

When you pass in `obj`, you're passing in a reference to the global variable 
`a`, and giving in the local (inside the function) alias of `obj`. But when you 
then assign the local variable (alias) `obj` to a new value, you've just 
reassigned the alias (and not affected the underlying object).

By contrast, when you use the alias to add/remove/alter properties, you are 
actually using the alias to modify the shared object reference, hence you 
modify the same underlying object that `a` points to.

What you're trying to do (and can't) is make the reassignment of the value that 
`obj` now points to also affect where `a` points to.

The key difference here is the idea of an alias/reference as opposed to a 
pointer (to put it in C terms). You can't affect *where* `a` points to from 
inside the function, but you can affect the *object* `a` points to.

Hope that helps.

--Kyle




 

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to