Context here means the this binding of a function. If you start with a desire to write pure functions and to structure your program as a composition of pure functions, then you want to avoid the this keyword. Functions that use this are impure. But sometimes this is unavoidable. For example, you might be writing a lifecycle method for a React component and need a value from this.props. In that case, you need an abstraction which provides those values to your pure function as arguments so the pure function doesn’t lose its purity. A higher-order function is one way to create that abstraction. If you just want to change a function’s this binding then Function.prototype.bind is definitely all you need.
What does that mean though?
It sounds like a “context” is given to “context-free” functions. But are they actually context-free, then?
What does this accomplish where just calling the standard
bindmethod wouldn’t suffice?It’s probably bad and likely eliminates referential transparency.
Context here means the
thisbinding of a function. If you start with a desire to write pure functions and to structure your program as a composition of pure functions, then you want to avoid thethiskeyword. Functions that usethisare impure. But sometimesthisis unavoidable. For example, you might be writing a lifecycle method for a React component and need a value fromthis.props. In that case, you need an abstraction which provides those values to your pure function as arguments so the pure function doesn’t lose its purity. A higher-order function is one way to create that abstraction. If you just want to change a function’sthisbinding thenFunction.prototype.bindis definitely all you need.