Template:Function Constructor

From Noisebridge Wiki
Revision as of 11:36, 19 February 2026 by Maintenance script (talk | contribs) (Imported from Noisebridge wiki backup)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
// 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());

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.