Template:Function Constructor

From Noisebridge
Jump to navigation Jump to search

<source lang="javascript"> // Colorized is a constructor. function Colorized(name, favoriteColor) {

 this.name = name;
 this.favoriteColor = favoriteColor;

}

// c is an instance of Colorized. var c = new Colorized("Mary", "red"); alert(c.toString()); </source> A toString method is available on every native object. This is because toString is defined on Object.prototype and Object.prototype is at the base the prototype chain.