Instance method : Member Function « Object Oriented « JavaScript Tutorial






<HTML>
<HEAD>
<TITLE>Instance method demo</TITLE>
</HEAD>
   <BODY>
   <H1>
   <SCRIPT>
   function Rectangle(height, width){
      this.height =  height;
      this.width = width;
   }
   function calc_Area () {
      return this.height * this.width;
   }

   function to_String() {
      return this.height + " by " +this.width;
   }
   Rectangle.prototype.calcArea = calc_Area;
   Rectangle.prototype.toString = to_String;

   var theRectangle = new Rectangle (2, 42);
   document.write(theRectangle);
   </SCRIPT>
   </H1>
   </BODY>
</HTML>








25.4.Member Function
25.4.1.Defining the object methods outside of the factory functions and then pointing to them
25.4.2.Create an Object with member method
25.4.3.Add member function
25.4.4.Adding method to a class using prototype
25.4.5.Custom objects and associative object arrays
25.4.6.Instance method
25.4.7.Call object member function