Call an object method - Javascript Object

Javascript examples for Object:Object Method

Description

Call an object method

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script>
function Guy(person_name) {//from w w w.j  av  a  2 s  .  com
  this.name = person_name;
  this.age = 32;
  this.say = function() {console.log(this.name + " is " + this.age);};
}
var bob = new Guy("Bob");

      </script> 
      <a href="#" onclick="bob.say()">eh</a>  
   </body>
</html>

Related Tutorials