Here is what I did.
var A = function() {
var internal = 0;
this.increment = function() {
return ++internal;
};
};
var B = function() {};
// inherit from A
B.prototype = new A;
//first case
x = new B;
y = new B;
//second case
z = new A;
z1 = new A;
alert(x.increment() + " - " + y.increment());
alert(z.increment() + " - " + z1.increment());
The private variables are behaving like static variables in first case, where as they are behaving like normal variables in second case.
1) Is there something we can conclude from above behaviour about private variables OR anything else?
2) One supplementary question that just popped up - When we add properties and methods to a constructor function using prototypes, there is only one method, and this is shared among all the instances(objects) created, same thing applied to variables?