CopyAndPaste

random programming notes

Javascript Private Variable Through Closure

Defining Javascript class private instance variable Example:

1
2
3
4
5
6
7
function MyClass(a) { // constructor
  this.getA = function() { return a; }
}

MyClass.prototype.myFunc = function() {
  return this.getA() + 1000; // do something with a 
}