var Counter = function (counter) { this.counter = counter; this.increment = function (b) { this.counter += b; }; }; var Counter2 = function (counter) { this.counter = counter; }; Counter2.prototype.increment = function (b) { this.counter += b; }; var counter_0 = new Counter(0); var counter_1 = new Counter(1); var counter2_0 = new Counter2(0); var counter2_1 = new Counter2(1); counter_0.increment = function (b) { this.counter += b*2; } counter_0.increment(2); counter_1.increment(2); console.log("Counter 0: " + counter_0.counter); console.log("Counter 1: " + counter_1.counter); Counter2.prototype.increment = function (b) { this.counter += b*2; }; counter2_0.increment(2); counter2_1.increment(2); console.log("Counter2 0: " + counter2_0.counter); console.log("Counter2 1: " + counter2_1.counter);