JavaScript | Function Call
It is a predefined javascript method, which is used to write methods for different objects. It calls the method, taking the owner object as argument. The keyword this refers to the “owner” of the function or the object it belongs to.
Syntax:
call()
Return Value: It calls and returns a method with the owner object being the argument.
Example 1: It uses call() method to call the employee as argument.
<!DOCTYPE html> <html> <head> <title> JavaScript Function Call </title> </head> <body> <h1>GeeksforGeeks</h1> <h2>JavaScript Function Call</h2> <p> It calls the employee details of emp2 </p> <p id="GFG"></p> <!-- Script to use call() method and display the emp2 details --> <script> var employee = { details: function() { return this.name + " " + this.id; } } var emp1 = { name:"Geeks", id: "234412", } var emp2 = { name:"G4G", id: "434556", } var x = employee.details.call(emp2); document.getElementById("GFG").innerHTML = x; </script> </body> </html> |
Output:

Example 2: This example describes the use of function call with arguments.
<!DOCTYPE html> <html> <head> <title> The call() Method with Arguments </title> </head> <body> <h1>GeeksforGeeks</h1> <h2>JavaScript Function Call</h2> <p> It calls the employee details of emp2 </p> <p id="GFG"></p> <script> var employee = { details: function(designation, experience) { return this.name + " " + this.id + "<br>" + designation + "<br>" + experience; } } var emp1 = { name:"A", id: "123", } var emp2 = { name:"B", id: "456", } var x = employee.details.call(emp2, "Manager", "4 years"); document.getElementById("GFG").innerHTML = x; </script> </body> </html> |
Output:

Recommended Posts:
- How to call function from it name stored in a string using JavaScript?
- JavaScript | Call a function after a fixed time
- How to call a function that return another function in JavaScript ?
- What is the difference between call and apply in JavaScript?
- Call multiple JavaScript functions in onclick event
- Difference between Call by Value and Call by Reference
- How to call PHP function on the click of a Button ?
- Call a parent window function from an iframe
- How to call PHP function from string stored in a Variable
- How to call a function automatically after waiting for some time using jQuery?
- How to remove error Call to undefined function curl_init()?
- Scala | Functions Call-by-Name
- Scala | Methods to Call on a Map | Set-1
- Print PHP Call Stack
- How to make a call-able link using HTML ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



