Return value from object's function - Javascript Function

Javascript examples for Function:Function Return

Description

Return value from object's function

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body>   
      <script type="text/javascript">
var person = function(name){
   var tmp = {};//w  w w  .  j  av a2 s .  c  o  m
   tmp.name = name;
   tmp.printName = function(){
        return tmp.name;
   }
   return tmp;
}
var joza = new person("Joe");

      </script>   
      <script type="text/javascript">
document.write(joza.printName());

      </script>    
   </body>
</html>

Related Tutorials