I am reading Nicholas C. Zakas's JavaScript for Web Developers Third Edition (old, I know), and I am having trouble understanding why static private variables/functions are static in the first place. I understand that if I declared a constructor with private variables/functions, all of its instances would have their own private variables/functions, like in one of Zakas's examples:
function MyObject(){
//private variables and functions
var privateVariable = 10;
function privateFunction(){
return false;
}
//privileged methods
this.publicMethod = function (){
privateVariable++;
return privateFunction();
};
}
So how would putting private variables/functions in private scopes make the variables static? Is it just because they're enclosed in a private scope, or is there something I'm overlooking? Here's one of Zakas's examples on static private variables:
(function(){
//private variables and functions
var privateVariable = 10;
function privateFunction(){
return false;
}
//constructor
MyObject = function(){
};
//public and privileged methods
MyObject.prototype.publicMethod = function(){
privateVariable++;
return privateFunction();
};
})();