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