Consider the following code snippet:
function C1() { // private variable in the constructor a = 1; } C1.prototype.f1 = function() { console.log( "a=" + a ); } C1.prototype.f2 = function() { a = 2; process.nextTick( this.f1 ); } o = new C1(); o.f1(); o.f2(); The output observed is:
a=1 a=2 I thought private variables aren't accessible outside of the Constructor function ?
var a = 1;. Simply setting it can create a global. stackoverflow.com/q/1470488