Call function when calling object without method - Javascript Object

Javascript examples for Object:Object Property

Description

Call function when calling object without method

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  av  a  2  s .c  o  m
var test = function() {
    console.log('hello');
    return {
        moo : function() {
            console.log('moo');
        }
    }
};
var obj = test();
obj.moo();
    }

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

Related Tutorials