I have JavaScript code as below;
var foo = (function() {
//Private vars
var a = 1;
return {
//Public vars/methods
a: a,
changeVar: function () {
a = 2;
}
}
})();
Now I am not sure how the syntax for public vars/methods works ? Could you please corelate how just "returning" the vars/methods makes them as public ?
Thank you.
apublic. You're returning an object with a property of the same name, and you've set it to the same value. When youchangeVar, you're changing the property, not the original variable.