brokethebuildagain
brokethebuildagain

Reputation: 2191

Underscore.js _.partial with _ as argument not working

I'm using Backbone and Underscore.

According to Underscore.js's documentation for the _.partial(function, *args) function:

You may pass _ in your list of arguments to specify an argument that should not be pre-filled, but left open to supply at call-time.

Does anyone have a working example of this? I am creating the partial call within a view like this:

this.filterCollection = _.partial(filterFn, _, searchTerm);

Where filterFn looks like:

function(license, key) {
    var organization;
    organization = App.organizations.get(license.get('organization_id'));

    if (license.isNew()) {
        return true; // Always include new models in the search.
    } else {
        return (organization && organization.get('name').indexOf(key) !== -1);
    }
}

I'm calling it in the view like this:

this.filterCollection(model)

The filterFn crashes on the line: organization = App.organizations.get(license.get('organization_id')); because license has no method get.

When I inspect license in Chrome, it points to:

Object function (obj) {
    if (obj instanceof _) return obj;
    if (!(this instanceof _)) return new _(obj);
    this._wrapped = obj;
}

Upvotes: 3

Views: 1001

Answers (1)

brokethebuildagain
brokethebuildagain

Reputation: 2191

Looks like they just added the option to use _ as an argument in version 1.6.0. No wonder I couldn't find much documentation on it. :)

Upvotes: 4

Related Questions