Pass function in an object literal with parameters - Javascript Object

Javascript examples for Object:Object Literal

Description

Pass function in an object literal with parameters

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">
//Define the function
var need = {//from  w  w  w .j  av a2  s. co m
  myFunc:function(token){
   console.log(token)
  }
};
// Invoking
need['myFunc'](1);
//dynamic invoke
var dynamicInvoke = 'myFunc';
need[dynamicInvoke](2);

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

Related Tutorials