This is due to the line
this.counter += amount;
What happens? this.counter
doesn't find property counter on the instance, so it takes it from the prototype, but when it comes to setting, it sets it on the instance
var fido = new Dog("fido");
console.log(fido.hasOwnProperty('counter')); // false
fido.add(1);
console.log(fido.hasOwnProperty('counter')); // true
Remember it is shorthand for
this.counter = this.counter + amount;
/* ↑ ↑
instance |
prototype */
As for letters, that is working as expected because push
is happening on the Object in the prototype - you're not setting a new instance variable. If you were setting an instance variable, it may still work because Objects are assigned to variables by reference, i.e.
var a = {}, b = a;
b.foo = 'bar';
a.foo; // "bar";