Today I learned that if for example I have an object:
var foo = {a: 1, b: { ... }}
And I pass it to a function:
function test(foo) {
foo.b
}
It has to load the whole foo
object into the function’s scope to access
the b
property, which increases the memory consumption.
The advice in the book is to always pass only what you need instead:
function test(b) {
b
}
test(foo.b)
My question if that's is true? and why? the object is passed by reference.