Apply/Call with constructor - Javascript Object

Javascript examples for Object:Constructor

Description

Apply/Call with constructor

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">
function Foo(a,b,c) {
    if( arguments.length === 0 )// w  w w. ja  v  a 2s.  c  o m
        return this;
    this.a = a; 
    this.b = b; 
    this.c = c;
}
var my = new Foo;
Foo.apply(my, ["a", "b", "c"]);
console.log(my);

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

Related Tutorials