Skip to content

2754. Bind Function to Context 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
type Fn = (...args) => any;

declare global {
  interface Function {
    bindPolyfill(obj: Record<any, any>): Fn;
  }
}

Function.prototype.bindPolyfill = function (obj): Fn {
  return (...newArgs) => this.call(obj, ...newArgs);
};