How to use the underscore.bind function in underscore

To help you get started, we’ve selected a few underscore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / underscore_v1.x.x / test_underscore-v1.js View on Github external
_.isEqual(1);


/**
 * _.range
 */
_.range(0, 10)[4] == 4
// $ExpectError string. This type is incompatible with number
_.range(0, 'a');
// $ExpectError string cannot be compared to number
_.range(0, 10)[4] == 'a';

/**
 * _.bind
 */
_.bind(function(a,b){return this.x+a+b;}, {x: 1}, 2, 3);
// $ExpectError number. This type is incompatible with the expected param type of function type
_.bind(123)

/**
 * _.bindAll
 */
_.bindAll({msg: 'hi', greet: function(){ return this.msg;}}, 'greet');
_.bindAll({msg: 'hi', greet: function(){ return this.msg;}}, 'greet', 'toString');
_.bindAll({msg: 'hi', greet: function(){ return this.msg;}}, ['greet'], 'toString');




/**
 * _.extend
 */
github jaridmargolin / s3-site / lib / bucket.js View on Github external
Bucket.prototype.uploadFile = function (filePath, callback) {
  var fileKey = filePath.replace(this.options.srcPath, '').substr(1);

  fs.readFile(filePath, _.bind(function (err, fileBuffer) {
    var params = this._params({
      Key: fileKey,
      Body: fileBuffer,
      ContentType: mime.lookup(filePath)
    });

    // Remove all browser caching on specified
    // resources
    if (_.contains(this.options.noCache, fileKey)) {
      _.extend(params, {
        CacheControl: 'no-cache, no-store, must-revalidate',
        Expires: (new Date()).toISOString()
      });
    }

    this.s3.putObject(params, callback);
github categolj / categolj2-backend / src / main / resources / static / resources / app / js / admin / views / TabPanelView.js View on Github external
render: function () {
            this.$el.empty();
            this.$el.html(this.template({
                tab: this.model.get('id'),
                title: this.model.get('itemName')
            }));
            this.$('.panel-body').empty().html(this.bodyView.$el);
            this.alertPanel = new AlertPanelView({el: this.$('#alert-panel')});
            this.$tab.tab('show');

            this.listenTo(Backbone, 'exception', _.bind(this.showExceptionMessage, this)); // handle global event!
            return this;
        },
        changeBodyView: function (bodyView) {
github mozilla / fxa / packages / fxa-content-server / app / scripts / views / base.js View on Github external
trackChildView(view) {
    if (!_.contains(this.childViews, view)) {
      this.childViews.push(view);
      view.on('destroyed', _.bind(this.untrackChildView, this, view));
    }

    return view;
  },
github CartoDB / cartodb / lib / assets / core / javascripts / deep-insights / widgets / dropdown / widget-dropdown-view.js View on Github external
_bindGlobalClick: function () {
    $(document).bind('click.' + this.cid, _.bind(this._onGlobalClick, this));
  },
github gabrielhurley / js-openclient / keystone / v3.0 / user_project_membership.js View on Github external
_fetchUserMembership: function(project, userSpec, callback) {
    this._users.get({
      id: userSpec.id
    }, _.bind(function(err, user) {
      if (err) {
        callback(err);
        return;
      }

      this._fetchProjectRolesForUser(project, user, function(err, roles) {
        if (err) {
          callback(err);
          return;
        }

        callback(null, {
          id: user.id,
          name: user.name,
          email: user.email,
          roles: roles,
github nhn / tui.grid / src / js / model / dimension.js View on Github external
initialize: function(attrs, options) {
        Model.prototype.initialize.apply(this, arguments);

        this.columnModel = options.columnModel;
        this.dataModel = options.dataModel;
        this.domState = options.domState;

        this.on('change:fixedHeight', this._resetSyncHeightHandler);

        if (options.domEventBus) {
            this.listenTo(options.domEventBus, 'windowResize', this._onResizeWindow);
            this.listenTo(options.domEventBus, 'dragmove:resizeHeight',
                _.debounce(_.bind(this._onDragMoveForHeight, this)));
        }

        this._resetSyncHeightHandler();
    },
github Kitware / minerva / web_external / models / GeoJSONStyle.js View on Github external
strokeOpacity: 1,
        fill: true,
        fillOpacity: 0.75,
        fillColor: '#BEE37B',
        strokeRamp: 'Blues',
        strokeColorKey: null,
        fillRamp: 'Reds',
        fillColorKey: null,
        logFlag: false,
        linearFlag: true,
        clampingFlag: false,
        quantileFlag: false,
        minClamp: 0,
        maxClamp: 100000
    },
    ramps: _.map(colorbrewer, _.bind(function (ramp, name) {
        var n = "<ul class="m-color-ramp">";
        _.each(ramp[6], function (color, i) {
            n += "<li style="background-color: &quot; + color + &quot;">";
        });
        n += '</li></ul>';
        this[name] = {
            value: ramp[6],
            display: n
        };
        return this;
    }, {}))[0]
});
export default GeoJSONStyle;
github galaxyproject / galaxy / client / galaxy / scripts / mvc / list / list-view.js View on Github external
_renderSearch: function($where) {
            $where.find(".controls .search-input").searchInput({
                placeholder: this.searchPlaceholder,
                initialVal: this.searchFor,
                onfirstsearch: _.bind(this._firstSearch, this),
                onsearch: _.bind(this.searchItems, this),
                onclear: _.bind(this.clearSearch, this)
            });
            return $where;
        },
github chrisjpowers / air-drop / lib / air-drop.js View on Github external
setTimeout(function() {
      orderedAsync.concat(package.pathsToAdd, _.bind(package._addPath, package), function(err, paths) {
        if (err) throw err;
        var currentFilePaths = _(package.paths).map(function(p) { return p.path; });
        paths.forEach(function(p) {
          if (currentFilePaths.indexOf(p.path) == -1) {
            package.paths.push(p);
            currentFilePaths.push(p.path);
          }
        });
      });
    }, 0);
  },