Create Public/Private function structure - Javascript Object

Javascript examples for Object:Private Member

Description

Create Public/Private function structure

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  w  w  .  j a  v  a2  s  .  co  m*/
function sumOfPrevious(n){
 return (function privateFunc(n){
  if (n == 1)
    return 1;
  else
    return n + privateFunc(n - 1);
  })(n);
}
console.log(sumOfPrevious(9));
    }

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

Related Tutorials