Skip to content

Instantly share code, notes, and snippets.

@Omkaragrawal
Created May 18, 2020 23:19
Show Gist options
  • Save Omkaragrawal/35b2aea42e351f87923bb679aaa3436d to your computer and use it in GitHub Desktop.
Save Omkaragrawal/35b2aea42e351f87923bb679aaa3436d to your computer and use it in GitHub Desktop.
function f() {
return this.a;
}
var g = f.bind({a: 'azerty'});
console.log(g()); // azerty
var h = g.bind({a: 'yoo'}); // bind only works once!
console.log(h()); // azerty
var i = f.bind({a: "bounded f for i"}); // but can bind original function again for a new output
console.log(i()); // bounded f for i
var o = {a: 37, f: f, g: g, h: h, i:i};
console.log(o.a, o.f(), o.g(), o.h(), o.i()); // 37,37, azerty, azerty, bounded f for i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment