1

I just started using jQuery boilerplate and i am unsure about the use of local variables vs object properties. When a function on the prototype (Plugin.prototype) has makes use of values that do not need to be shared with rest of the functions should i use var? Also is it OK to assign object properties in the functions themselves or should all values be store in the constructor?

Thanks!

Frederick M. Rogers
  • 841
  • 4
  • 14
  • 37
  • 2
    You should always declare your variables in the lowest scope possible. It's also absolutely fine to assign object properties anywhere you require – Rory McCrossan Mar 04 '17 at 16:16
  • if you don't use `var` (or `let`,`const`), your variable will be created in global scope – scraaappy Mar 04 '17 at 16:32
  • @RoryMcCrossan That makes sense, since the constructor will load it's properties with each instance, it would be waste to load anything that is not shared. So in the case of a local value `var` (or `let`) is fine in a prototype function? – Frederick M. Rogers Mar 04 '17 at 18:00

0 Answers0