Sometimes such methods are used to keep a reference to variables or create a singleton. Thus, we will call createVariable only once. What are the pros and cons of this approach?
function createVariable() {
return true;
}
function useVariable() {
if(!useVariable.someVar) {
useVariable.someVar = createVariable();
}
}
useVariable();
useVariable();
useVariable();
I am grateful to all the ideas and recommendations. I do not want to create a singleton. I just want to keep the link variable at the function level. Without pollute the global scale.
source
share