Underscore.js _.partial with _ as an argument does not work

I use Backbone and Underscore.

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

You can pass _ to your argument list to specify an argument that should not be prefilled but left open for submission during a call.

Does anyone have a working example? I create a partial call in this form:

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

Where the filter Fn is as follows:

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 call it in the form as follows:

this.filterCollection(model)

Filter Fn failed on line: organization = App.organizations.get(license.get('organization_id'));because it licensedoes not have a method get.

When I check licensein Chrome, it points to:

Object function (obj) {
    if (obj instanceof _) return obj;
    if (!(this instanceof _)) return new _(obj);
    this._wrapped = obj;
}
+3
source share
1 answer

, _ 1.6.0. , .:)

+4

All Articles