While delving into the world of AngularJS, I stumbled upon an interesting revelation - when objects are placed in a prototype object, any instances inheriting from that prototype will alter the prototype's objects upon assignment.
For example:
function Person(name) {this.name = name;}
Person.prototype = {species : "homo-sapiens" , characteristics : { "legs" : 2 , "height" : 175}}
var joe = new Person("joe");
joe.characteristics.legs = 1;
console.log(Person.prototype.characteristics) //Object {legs: 1, height: 175}
What this demonstrates is that the instance (in this case, 'joe') associated with the prototype altered the value of the object on the prototype itself because it inherited an object ('characteristics'), as opposed to a primitive value.
So, the question arises: Should prototypes primarily contain primitive values? In most scenarios, you would not desire an instance to modify the prototype's value. However, Angular.js allows for this behavior, albeit in rare cases where a child instance needs to write to the prototype.
If you do wish to place an object on the prototype without allowing instances to overwrite its properties upon assignment, what approach could be taken?