topical media & game development

talk show tell print

professional-javascript-03-PrototypeExample.htm / htm

  <script type="text/javascript">
  function Car() {
  Car.prototype.color = "red";
  Car.prototype.doors = 4;
  Car.prototype.mpg = 23;
  Car.prototype.drivers = new Array("Mike", "Sue");
  Car.prototype.showColor = function () {
  var oCar1 = new Car();
  var oCar2 = new Car();
  alert(oCar1.drivers);    //outputs "Mike,Sue,Matt"
  alert(oCar2.drivers);    //outputs "Mike,Sue,Matt"

(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.