buchuitoudegou / Tutorial

0 stars 0 forks source link

an implement of bind #3

Open buchuitoudegou opened 5 years ago

buchuitoudegou commented 5 years ago
Function.prototype.Bind = function(obj) {
  const self = this;
  return function() {
    self.call(obj, ...arguments);
  }
}

function demo(cc, ll) {
  console.log(this.a);
  console.log(cc);
  console.log(ll);
}
let e = demo.Bind({ a: 1 });
e('cc', 'll');

expected out:

1
cc
ll