// No arguments bound.
fn = bind(&foozle, foo);
fn('foo1', 'bar1');
Outputs:
called foozle('foo1', 'bar1')
And finally:
// Mix of bound and unbound args.
fn = bind(&foozle, foo, 'foo2');
fn('bar2');
Outputs:
called foozle('foo2', 'bar2')
Note that bind() doesn’t do any checking of argument counts, so it’s up to you to keep track of the usage, same as if you were calling the method directly.
// fn() will be foo.baz()
fn = bind(&baz, foo);
// Now obj.callback() will be fn, which is foo.baz()
obj = new Bar(fn);
…and so in this example…
obj.callback(true);
…will output…
called baz(true)
Just writing that all out because this is one of my main use cases for the entire binding mechanism and it took a little fiddling around to get it working.