check function parameter and provide default value - Javascript Function

Javascript examples for Function:Function Argument

Description

check function parameter and provide default value

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  a v  a2 s .c  o  m
var B = (function () {
    return function (n) {
        var name = n || 'Test';
        this.sayHello = function () {
            console.log("Hi " + name);
        }
    }
})()
var b1 = new B("xxx");
var b2 = new B("yyy");
var b3 = new B();
b1.sayHello();
b2.sayHello();
b3.sayHello();
    }

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

Related Tutorials