Sobes.tech
Junior — Senior

Create a custom implementation of Function.prototype.bind with support for partial application

livecode

Task condition

You need to write your own version of the bind method, which will bind the function's context and allow passing some arguments in advance.

const obj = {
  a: 1,
  say(arg1, arg2) {
    if (arg1 !== undefined && arg2 !== undefined) {
      console.log(this.a * arg1 * arg2);
    } else {
      console.log(this.a);
    }
  }
};

const fn = obj.say;
fn.bind(obj, 1)(2);

Your implementation should work correctly both when all arguments are passed and when only some are provided.