Skip to content

Instantly share code, notes, and snippets.

@stetsd
Created August 20, 2018 15:05
Show Gist options
  • Save stetsd/5a6a4c6cf2f88edb9c2bdf07928bfdfa to your computer and use it in GitHub Desktop.
Save stetsd/5a6a4c6cf2f88edb9c2bdf07928bfdfa to your computer and use it in GitHub Desktop.
jj
function bind(method, context) {
var args = Array.prototype.slice.call(arguments, 2);
return function() {
var a = args.concat(Array.prototype.slice.call(arguments, 0));
return method.apply(context, a);
}
}
function Man(name){
this.name = name;
}
function Worker(){}
Worker.prototype.doWork = function(ef){
console.log(this.name + ' is working ' + ef);
}
Worker.prototype.bind = bind;
let bob = new Man('Bob');
let worker = new Worker();
worker.bind(worker.doWork, bob)('strongly!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment