JS Built-ins
Functioncallbeginner

Function.prototype.call() β€” bind this

πŸ“– Usage Example
function greet() { return this.name }
greet.call({ name: 'Bob' })  // β†’ 'Bob'

call() invokes a function immediately with a specified this value.

fn.call(thisArg)

call() invokes a function with a specified this value. The first argument becomes this inside the function.

Challenge: Use call() so that greet returns the name from its this context.

πŸ’‘ Hints (2)
  • β€’ `fn.call(ctx, arg1, arg2)` sets `this` to `ctx`.
  • β€’ Pass the object as the first argument to `call()`.