Created
August 20, 2018 15:05
-
-
Save stetsd/5a6a4c6cf2f88edb9c2bdf07928bfdfa to your computer and use it in GitHub Desktop.
jj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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