topical media & game development

talk show tell print

professional-javascript-03-ConstructorExample.htm / htm

  <title>Constructor Example</title>
  <script type="text/javascript">
  function Car(sColor, iDoors, iMpg) {
      this.color = sColor;
      this.doors = iDoors;
      this.mpg = iMpg;
      this.showColor = function () {
  var oCar1 = new Car("red", 4, 23);
  var oCar2 = new Car("blue", 3, 25);
  oCar1.showColor();    //outputs "red"
  oCar2.showColor();    //outputs "blue"

(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.