JavaScript code by including four ways of creating an object with two fields:

JavaScript code by including four ways of creating an object with two fields:

<html>
 <body>
  <script>
   var o1 = { x: 100, y: 200 } ;
   document.writeln(o1.x) ;
   document.writeln("<br />") ;
   var o2 = {} ;
   o2.x = 100 ;
   o2.y = 200 ;
   document.writeln(o2.x) ;
   document.writeln("<br />") ;
   var o3 = new Object() ;
   o3.x = 100 ;
   o3.y = 200 ;
   document.writeln(o3.x) ;
   document.writeln("<br />") ;
   function XYObject(initX,initY) {
    this.x = initX ;
    this.y = initY ;
   }
   var o4 = new XYObject(100,200) ;
   document.writeln(o4.x) ;
   document.writeln("<br />") ;
  </script>
 </body>
</html>

Comments

Popular posts from this blog

Artificial Intelligence

The taxonomy of CASE Tools

Zoho Second round - adding a digit to all the digits of a number