Skip to content

Instantly share code, notes, and snippets.

@dd1994
Last active December 12, 2015 05:14
Show Gist options
  • Save dd1994/38efc9fcfaac17c5c56f to your computer and use it in GitHub Desktop.
Save dd1994/38efc9fcfaac17c5c56f to your computer and use it in GitHub Desktop.
implement Function.prototype.bind
'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