underscore icon indicating copy to clipboard operation
underscore copied to clipboard

_.bind supports _.partial application, but not its non pre-filled argument syntax with _

Open Majeure opened this issue 8 years ago • 5 comments

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

Majeure avatar Oct 26 '15 17:10 Majeure

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.

jdalton avatar Oct 26 '15 17:10 jdalton

I'm good with it. Note that this will invalidate the first two options in https://github.com/jashkenas/underscore/issues/2214#issuecomment-113207896.

jridgewell avatar Oct 26 '15 22:10 jridgewell

I'd rather wait til 2.0 before anything radical is done to bind. Though we could definitely work towards 2.0/underdash soon

megawac avatar Oct 26 '15 22:10 megawac

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.

jdalton avatar Oct 26 '15 23:10 jdalton

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.

sament-sugarcrm avatar Oct 25 '17 18:10 sament-sugarcrm