I have a very simple JS code as below;
var Worker = function (name) {
this.name = name;
}
Worker.prototype.jobs = 0;
Worker.prototype.Work = function () {
console.log("jobs finished", this.name, ++this.jobs);
}
var ca = new Worker("ca");
var cb = new Worker("cb");
ca.Work();// shows 1
cb.Work();// shows 1 (Q: Why is this not printed 2 ?)
Now the above prints 1 for this.jobs twice. I was expecting that since the property "jobs" is defined on the prototype, it would be a shared one (and not really a different copy for each instance). However that does not seem to be the case. Where is my understanding wrong and what am I missing ?