• Jump To … +
    underscore.array.builders.js underscore.array.selectors.js underscore.function.arity.js underscore.function.combinators.js underscore.function.iterators.js underscore.function.predicates.js underscore.object.builders.js underscore.object.selectors.js underscore.util.existential.js underscore.util.strings.js underscore.util.trampolines.js
  • underscore.object.selectors.js

  • ¶

    Underscore-contrib (underscore.object.selectors.js 0.0.1) (c) 2013 Michael Fogus, DocumentCloud and Investigative Reporters & Editors Underscore-contrib may be freely distributed under the MIT license.

    (function(root) {
  • ¶

    Baseline setup

  • ¶

    Establish the root object, window in the browser, or global on the server.

      var _ = root._ || require('underscore');
  • ¶

    Helpers

  • ¶

    Create quick reference variables for speed access to core prototypes.

      var concat  = Array.prototype.concat;
  • ¶

    Mixing in the object selectors

      _.mixin({
  • ¶

    Returns a function that will attempt to look up a named field in any object that it's given.

        accessor: function(field) {
          return function(obj) {
            return (obj && obj[field]);
          };
        },
  • ¶

    Like _.pick except that it takes an array of keys to pick.

        selectKeys: function (obj, ks) {
          return _.pick.apply(null, concat.call([obj], ks));
        }
      });
    
    })(this);