In node modules, should I use closures or use their private variables?
-
I am programming for prototypal inheritance, and thus will be extending other modules (also my own). I thus plan to write a normal object with all public methods and variables in it, and then have the module.exports constructor return a copy of it. I am wondering if I should encapsulate private variables inside of the returned object using closure-based getters and setters or simply keep them out of the object entirely and instead in the entire module space, which is designated to be private?
-
Answer:
Module.exports is just an object, not necessarily a constructor. It's personal preference. Keeping variables in the module's scope will make things much cleaner.
Brian Chu at Quora Visit the source
Related Q & A:
- Can I use a variable to name other variables?Best solution by Stack Overflow
- How do I make my Myspace 2.0 private?Best solution by Yahoo! Answers
- How do I make my Q and As private?Best solution by Yahoo! Answers
- How do I set my Q&A to private?Best solution by Yahoo! Answers
- How do I make my aim screen name private?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.