Use var to create function - Javascript Function

Javascript examples for Function:Function Variable

Description

Use var to create function

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(){/*w w  w .  ja va  2s . com*/
var init = function(){
     return {
      hello: function(){ console.log("hello"); },
      world: function(){ console.log("world"); }
     };
    };
var f = init();
    f.hello();
    f.world();
    }

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

Related Tutorials