call a method from within a constructor - Javascript Object

Javascript examples for Object:Constructor

Description

call a method from within a constructor

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from  w ww  .  j  a  v a 2 s. c  o m*/
function my(x, y){
    this.x = x;
    this.y = y;
    this.debugMessage = function(){
        document.getElementById("messageArea").innerHTML =
                "my(x, y) constructor called";
    };
}
var myPoint = new my(10, 20).debugMessage();
    }

      </script> 
   </head> 
   <body> 
      <div id="messageArea"></div>  
   </body>
</html>

Related Tutorials