logo
logo

Context with Call

Beginner

Context with Call

Write a function called
greet
that logs a greeting message to the console with the
name
property of the object it is passed to as an argument.
The function will use the
call()
method to execute in the context of the object, so you shouldn't have to change the
greet
function declaration.
Console
Submit
Solution
00:00

Solution Walkthrough for Context with Call

By using
call()
, we can specify the object that should be used as the context for the function execution. In this case, we pass the
person
object as the first argument to
call()
, which sets
this
inside the
greet
function to the
person
object.