JS Built-ins
Functionbindbeginner

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

πŸ“– Usage Example
function greet() { return this.name }
const hi = greet.bind({ name: 'Alice' })
hi()  // β†’ 'Alice'

bind() returns a new function with this permanently set to the provided object.

fn.bind(thisArg)

bind() returns a new function with this permanently set to the provided value.

Challenge: Use greet.bind({name: 'Bob'}) and verify the bound function returns 'Bob'.

πŸ’‘ Hints (2)
  • β€’ `bind()` returns a new function β€” you must call it separately.
  • β€’ The bound `this` cannot be changed by `call` or `apply`.