Reputation: 1069
I am creating a node.js based website where I ask users to fill forms with large number of details, so each one of them becomes a parameter.
The way I have written the code is that I keep passing these parameters from one function to another. I think these parameters go through at least 4 functions as my code has gotten obnoxious about separate model and controller.
My question is what is the cost of passing so many parameters in JavaScript. Will they pass my parameters around as some reference / pointer or the entire object will get copied. I really do not want the entire object to be copied because some of the parameters can contain large amount of text or digital information.
Is there any known source of information about this? First 5 results on google didn't yield useful results.
Upvotes: 1
Views: 893
Reputation: 1087
Objects are not copied. Semantically speaking, references to the objects are copied, but internally that will not even happen until you alter them (see http://en.wikipedia.org/wiki/Copy-on-write).
Argument passing in javascript by itself is incredibly cheap since there is no type checking or checking for required parameters.
Upvotes: 6