Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#2328·underscore

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

Author: MajeureCreated Oct 26, 2015Updated Dec 16, 2021
Labelsbreaking changedocumentation

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/

javascript
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

Source: jashkenas/underscore

View original on GitHubView discussion on GitHub