Template:Function Constructor: Difference between revisions
Jump to navigation
Jump to search
Created page with "== Functions Double as Constructor == <source lang="javascript"> // Colorized is a constructor. function Colorized(name, favoriteColor) { this.name = name; this.favoriteC..." |
|||
| Line 1: | Line 1: | ||
<source lang="javascript"> | <source lang="javascript"> | ||
// Colorized is a constructor. | // Colorized is a constructor. | ||
Latest revision as of 12:13, 12 August 2014
<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.