So if we can get past the \"should you?\" question ... does anyone know how to set the value of an integer in prototype?
JavaScript has both number primitives and Number
objects. Number primitives are immutable (like all primitives in JavaScript). The numeric value of a Number
object is also immutable. So your add
method can only return the updated value. You can create your own number-like object, of course, with a mutable value.
Details about number immutability and your own number object in this other answer (didn't realize that question was a duplicate when answering it).