Solution Review: Bind Function
This lesson will explain the solution to the problem in the previous lesson.
We'll cover the following...
Solution #
Press + to interact
const bind = (fn, obj) => (...args) => fn.apply(obj, args)function multiply(a) {console.log(this.val * a.val2);}var obj = {val : 2}function callingBind(){const bindFunc = bind(multiply, obj)bindFunc.call(this,{val2 : 2})}callingBind()
Explanation #
This problem involves applying your understanding of the JavaScript rest syntax and bind function.
We have to implement our own bind
function. To do that, we need to know what the bind function does. It returns a new function that wraps the original function. It has its ...