Learn JavaScript
call, apply and bind
26.1
Lesson

call()

call() allows a function or method to be declared in an object and executed by another object.

In the example given below, when we use call() with the object firstPerson, the value of this.name is Sam. The value of this.name changes to Oliver when we use call() with the object secondPerson.

We can use call() to write a method in an object and inherit the properties of the method into another object without writing the method all over again.