topical media & game development

talk show tell print

professional-javascript-04-ObjectMasqueradingCallExample.htm / htm



  <html>
  <head>
  <title>Example</title>
  </head>
  <body>
  <script type="text/javascript">
  function ClassA(sColor) {
      this.color = sColor;
      this.sayColor = function () {
          alert(this.color);
      };
  }
  
  function ClassB(sColor, sName) {
      //this.newMethod = ClassA;
      //this.newMethod(color);
      //delete this.newMethod;
      ClassA.call(this, sColor);
  
      this.name = sName;
      this.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.