JS Built-ins
Functionbindintermediate

Function.prototype.bind() β€” create double()

πŸ“– Usage Example
const fn = function() { return this.val }.bind({ val: 42 })
fn()  // β†’ 42

bind() works on both function declarations and function expressions.

bind() to create specialized functions

Bind the first argument of multiply to 2 to create a double function.

Challenge: Use multiply.bind(null, 2) to create double and verify double(4) === 8.

πŸ’‘ Hints (1)
  • β€’ Partial application with `bind` creates specialized functions from general ones.