Using fn.bind()
creates a new function with scope (and parameters) pre-configured
GIVEN we bind a scope to a function
WHEN we call the bound function with a custom object THEN the scope of this
refers to the given object
WHEN binding a string to String's toUpperCase
THEN calling the resulting function returns the upper case value of the string
WHEN binding Array's slice()
method THEN array-like values can dynamically be converted to an array
GIVEN we bind parameters to a function
WHEN binding the first parameter of a function THEN the bound function can be called just with the seconds parameter
Links
The MDN docs about `bind()`.
The ECMAScript Language Specification, 5 Edition, Section 15.3.4.5, when `bind()` was introduced.
Related Katas
function API
function.length
(as introduced in ES1)function.bind()
function.length
(with ES5 features)function.length
(with ES6 features)function.name
Arrow functions
Async Function
Difficulty Level
ADVANCED
First Published
16 October 2023
Stats
4 tests to solve