underscore
underscore copied to clipboard
_.bind supports _.partial application, but not its non pre-filled argument syntax with _
I don't know if this is intended behavior, but it seems all around confusing if so. My guess is this portion of _.bind was just left untouched when _.partial received this functionality. Here's the simplified reproduction of it in jsfiddle: http://jsfiddle.net/j3jpL4eb/1/
var foo = function(bar) {
console.log(bar); //this should always print 'bar' if non pre-filled arguments applied to bind's partial application as well, yet it has the value of underscore when not double wrapped
}
_.bind(foo, this, _)('bar'); //function (n){return n instanceof m?n:this instanceof m?void(this._wrapped=n):new m(n)}
_.bind(_.partial(foo, _), this)('bar'); //bar
Currently Underscore only supports placeholders in _.partial
.
From a feature parity perspective lodash supports placeholders in _.bind
.
It may be seen as a breaking change in Underscore so might have to wait until 2.0.
I'm good with it. Note that this will invalidate the first two options in https://github.com/jashkenas/underscore/issues/2214#issuecomment-113207896.
I'd rather wait til 2.0 before anything radical is done to bind. Though we could definitely work towards 2.0/underdash soon
I'm cool with deferring to 2.0. We should add it to a 2.0 issue or wiki entry so it's not forgotten then close out this issue.
If you're going to defer this to 2.0, I'd recommend adding a note to the documentation. It says to check _.partial documentation for the partial application, which leads the reader to believe that _.bind also supports it.