Custom objects and associative object arrays : Member Function : Object Oriented JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Object Oriented » Member Function »

 

Custom objects and associative object arrays

















<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 (35);
theRectangle.width = 10;
showProperties (theRectangle);
</SCRIPT>
</BODY>
</HTML>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Object Oriented
» Member Function