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:
- Call by Value Vs Call by Reference in JavaScript
- Difference between Call by Value and Call by Reference
- How to call a function that return another function in JavaScript ?
- 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 repeatedly every 5 seconds in JavaScript ?
- JavaScript Function.prototype.call() Method
- What is the difference between call and apply in JavaScript?
- Call multiple JavaScript functions in onclick event
- How to make GET call to an API using Axios in JavaScript?
- How to make POST call to an API using Axios.js in JavaScript ?
- How to call a parent method from child class in JavaScript?
- How to return the response from an asynchronous call in JavaScript ?
- Python - Call function from another function
- How to call PHP function from string stored in a Variable
- How to remove error Call to undefined function curl_init()?
- How to call PHP function on the click of a Button ?
- Call a parent window function from an iframe
- How to call a function automatically after waiting for some time using jQuery?
- How to call functions after previous function is completed in jQuery ?
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.


