In a function where I use several times the user id, what is the good practice:
Meteor.userId() or in publications this.userId)Another way to ask would be "is my locale variable a simple reference to the Meteor.userId() (calling it everytime) or is it a copy?
I agree that it might look as a micro-optimization, but I ask it more to learn and understand how Javascript works (in a meteor context).
Subsidiary question: Is it a question related to closure? I am still trying to figure that out.
Meteor.userId() just returns a plain old Javascript string. You can save it in a variable after the first call to it and use it without any consequences.
This isn't related to closures per se, but it is related to how Meteor's reactivity. As long as you are calling Meteor.userId() at least once in your function in a reactive context, Meteor will re-run the function when it changes.
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