topical media & game development

talk show tell print

professional-javascript-04-HybridExample.htm / htm



  <html>
  <head>
  <title>Example</title>
  </head>
  <body>
  <script type="text/javascript">
  function ClassA(sColor) {
      this.color = sColor;
  }
  
  ClassA.prototype.sayColor = function () {
      alert(this.color);
  };
  
  function ClassB(sColor, sName) {
      ClassA.call(this, sColor);
      this.name = sName;
  }
  
  ClassB.prototype = new ClassA();
  
  ClassB.prototype.sayName = function () {
      alert(this.name);
  };
  
  var objA = new ClassA("red");
  var objB = new ClassB("blue", "Nicholas");
  objA.sayColor();
  objB.sayColor();
  objB.sayName();
  
  </script>
   
  </body>
  </html>
  


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