C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Function call() methodThe JavaScript Function call() method is used to call a function contains this value and an argument provided individually. Unlike apply() method, it accepts the argument list. Syntaxfunction.call(thisArg, arg1,arg2,....,argn) ParameterthisArg - It is optional. The this value is given for the call to function. arg1,arg2,...,argn - It is optional. It represents the arguments for the function. Return ValueIt returns the result of the calling function along provided this value and arguments. JavaScript Function call() method ExampleExample 1Let's see a simple example of call() method. <script> function Emp(id,name) { this.id = id; this.name = name; } function PermanentEmp(id,name) { Emp.call(this,id,name); } document.writeln(new PermanentEmp(101,"John Martin").name); </script> Output: John Martin Example 2Let's see an example of call() method. <script> function Emp(id,name) { this.id = id; this.name = name; } function PermanentEmp(id,name) { Emp.call(this,id,name); } function TemporaryEmp(id,name) { Emp.call(this,id,name); } var p_emp=new PermanentEmp(101,"John Martin"); var t_emp=new TemporaryEmp(201,"Duke William") document.writeln(p_emp.id+" "+p_emp.name+"<br>"); document.writeln(t_emp.id+" "+t_emp.name);</script> Output: 101 John Martin 201 Duke William
Next TopicJavaScript Function
|