Last active
December 12, 2015 05:14
-
-
Save dd1994/38efc9fcfaac17c5c56f to your computer and use it in GitHub Desktop.
implement Function.prototype.bind
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
'use strict' | |
let bind = function (fn, obj) { | |
return function () { | |
fn.apply(obj, arguments) | |
} | |
} | |
let foo = function () { | |
console.log(this.a); | |
} | |
const obj = { | |
a: 2 | |
} | |
let bar = bind(foo, obj) | |
bar() | |
setTimeout(foo, 1000); | |
setTimeout(bar, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment