Search code examples
javascriptprototype-programming

If a prototype is changed, will this affect current instances?


Say I have this:

var _JS = function() {
  this.Constants = {
    True: 1,
    False: 0,
    Nil: null,
    Unknown: void(0),
  };
};

var JS = new _JS();

If I change it afterwards (add methods, using _JS.prototype.etc), can I call those methods on JS?


Solution

  • Yes, a prototype change affects all instances of the item whose prototype you modified.

    See example of a simple prototype modification: http://jsfiddle.net/JAAulde/56Wdw/1/