Function call() Method
Description
The call() method calls a function with a given
this value.
The call() method lets objects borrow methods from other objects.
Example
function fullName() {
return this.fName + " " + this.lName;
}
// Create a person Object
const person = {
fName: "John",
lName: "Doe"
}
// Use fullName on person
let name = fullName.call(person);
Try it Yourself »
Syntax
function.call(object, arguments)
Parameters
| Parameter | Description |
| function | Required. The function to call. |
| object | Required. The object to call with the function. |
| arguments | Optional. Array-like object with function arguments. |
Return Value
| Type | Description |
| Value | The result of the function. |
More Examples
Example
// Create a person Object
const person = {
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
// Create a person1 Object
const person1 = {
firstName:"John",
lastName: "Doe"
}
// Use fullName of person on person1
let name = person.fullName.call(person1);
Try it Yourself »
JavaScript Function Methods
Browser Support
call() is an ECMAScript3 (JavaScript 1999) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |