Skip large object as argument

General question:
Does this affect performance when a large object is passed as a vs parameter, when its own variable is passed?

Case: I wrote a component that controls Google Maps.
In each of the component methods, you need to pass the Google Maps object, since I do not want to set the map as a property on the component.

+7
javascript
source share
4 answers

When you pass an object as an argument to a function, the only thing that is copied is the handler of that object (the address in memory where the object is stored). The object itself is not cloned, so there is no extra cost when passing a large object as an argument.

If you pass a string, it is cloned, so in this case the length of the string is disturbing.

+6
source share

The size of an object does not affect performance, since objects in javascript are passed as a reference.

0
source share

There is a slight performance penalty, since the location of the object is called when it is sent to your method, but the ease of programming a new component or detecting errors in the object far exceeds the cost of ~ 1 millisecond.

0
source share

JavaScript always passes a value. But when an object is transferred, the meaning itself is a reference.

Therefore, performance will not be affected by the transfer of a large object, because the passed is a value that is just a reference to the object.

0
source share