Custom objects and associative object arrays : Member Function « Object Oriented « JavaScript Tutorial






<HTML>
<HEAD>
   <TITLE>Custom objects and associative object arrays</TITLE>
<SCRIPT>
function showProperties (theObject){
   for (i in theObject) {
      if (theObject[i] != null) {
          document.write(i + " : " + theObject[i] + "<br>");
           
      }
      else {
         document.write(i + "<br>");
      }
   }
   return;
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
// constructor function
function Rectangle(height, width){
   this.height =  height;
   this.width = width;
}

function calc_Area () {
   return this.height * this.width;
}
// turn the function into an object method
Rectangle.prototype.calcArea = calc_Area;

var theRectangle = new Rectangle (3, 5);
theRectangle.width = 10;
showProperties (theRectangle);
</SCRIPT>
</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