Make WordPress Core

Ticket #31514: 31514.patch

File 31514.patch, 101.6 KB (added by ocean90, 11 years ago)
  • src/wp-includes/js/underscore.js

     
    1 //     Underscore.js 1.6.0
     1//     Underscore.js 1.8.2
    22//     http://underscorejs.org
    3 //     (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
     3//     (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
    44//     Underscore may be freely distributed under the MIT license.
    55
    66(function() {
     
    1414  // Save the previous value of the `_` variable.
    1515  var previousUnderscore = root._;
    1616
    17   // Establish the object that gets returned to break out of a loop iteration.
    18   var breaker = {};
    19 
    2017  // Save bytes in the minified (but not gzipped) version:
    2118  var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
    2219
     
    2421  var
    2522    push             = ArrayProto.push,
    2623    slice            = ArrayProto.slice,
    27     concat           = ArrayProto.concat,
    2824    toString         = ObjProto.toString,
    2925    hasOwnProperty   = ObjProto.hasOwnProperty;
    3026
    3127  // All **ECMAScript 5** native function implementations that we hope to use
    3228  // are declared here.
    3329  var
    34     nativeForEach      = ArrayProto.forEach,
    35     nativeMap          = ArrayProto.map,
    36     nativeReduce       = ArrayProto.reduce,
    37     nativeReduceRight  = ArrayProto.reduceRight,
    38     nativeFilter       = ArrayProto.filter,
    39     nativeEvery        = ArrayProto.every,
    40     nativeSome         = ArrayProto.some,
    41     nativeIndexOf      = ArrayProto.indexOf,
    42     nativeLastIndexOf  = ArrayProto.lastIndexOf,
    4330    nativeIsArray      = Array.isArray,
    4431    nativeKeys         = Object.keys,
    45     nativeBind         = FuncProto.bind;
     32    nativeBind         = FuncProto.bind,
     33    nativeCreate       = Object.create;
    4634
     35  // Naked function reference for surrogate-prototype-swapping.
     36  var Ctor = function(){};
     37
    4738  // Create a safe reference to the Underscore object for use below.
    4839  var _ = function(obj) {
    4940    if (obj instanceof _) return obj;
     
    5344
    5445  // Export the Underscore object for **Node.js**, with
    5546  // backwards-compatibility for the old `require()` API. If we're in
    56   // the browser, add `_` as a global object via a string identifier,
    57   // for Closure Compiler "advanced" mode.
     47  // the browser, add `_` as a global object.
    5848  if (typeof exports !== 'undefined') {
    5949    if (typeof module !== 'undefined' && module.exports) {
    6050      exports = module.exports = _;
     
    6555  }
    6656
    6757  // Current version.
    68   _.VERSION = '1.6.0';
     58  _.VERSION = '1.8.2';
    6959
     60  // Internal function that returns an efficient (for current engines) version
     61  // of the passed-in callback, to be repeatedly applied in other Underscore
     62  // functions.
     63  var optimizeCb = function(func, context, argCount) {
     64    if (context === void 0) return func;
     65    switch (argCount == null ? 3 : argCount) {
     66      case 1: return function(value) {
     67        return func.call(context, value);
     68      };
     69      case 2: return function(value, other) {
     70        return func.call(context, value, other);
     71      };
     72      case 3: return function(value, index, collection) {
     73        return func.call(context, value, index, collection);
     74      };
     75      case 4: return function(accumulator, value, index, collection) {
     76        return func.call(context, accumulator, value, index, collection);
     77      };
     78    }
     79    return function() {
     80      return func.apply(context, arguments);
     81    };
     82  };
     83
     84  // A mostly-internal function to generate callbacks that can be applied
     85  // to each element in a collection, returning the desired result — either
     86  // identity, an arbitrary callback, a property matcher, or a property accessor.
     87  var cb = function(value, context, argCount) {
     88    if (value == null) return _.identity;
     89    if (_.isFunction(value)) return optimizeCb(value, context, argCount);
     90    if (_.isObject(value)) return _.matcher(value);
     91    return _.property(value);
     92  };
     93  _.iteratee = function(value, context) {
     94    return cb(value, context, Infinity);
     95  };
     96
     97  // An internal function for creating assigner functions.
     98  var createAssigner = function(keysFunc, undefinedOnly) {
     99    return function(obj) {
     100      var length = arguments.length;
     101      if (length < 2 || obj == null) return obj;
     102      for (var index = 1; index < length; index++) {
     103        var source = arguments[index],
     104            keys = keysFunc(source),
     105            l = keys.length;
     106        for (var i = 0; i < l; i++) {
     107          var key = keys[i];
     108          if (!undefinedOnly || obj[key] === void 0) obj[key] = source[key];
     109        }
     110      }
     111      return obj;
     112    };
     113  };
     114
     115  // An internal function for creating a new object that inherits from another.
     116  var baseCreate = function(prototype) {
     117    if (!_.isObject(prototype)) return {};
     118    if (nativeCreate) return nativeCreate(prototype);
     119    Ctor.prototype = prototype;
     120    var result = new Ctor;
     121    Ctor.prototype = null;
     122    return result;
     123  };
     124
     125  // Helper for collection methods to determine whether a collection
     126  // should be iterated as an array or as an object
     127  // Related: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
     128  var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
     129  var isArrayLike = function(collection) {
     130    var length = collection && collection.length;
     131    return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX;
     132  };
     133
    70134  // Collection Functions
    71135  // --------------------
    72136
    73137  // The cornerstone, an `each` implementation, aka `forEach`.
    74   // Handles objects with the built-in `forEach`, arrays, and raw objects.
    75   // Delegates to **ECMAScript 5**'s native `forEach` if available.
    76   var each = _.each = _.forEach = function(obj, iterator, context) {
    77     if (obj == null) return obj;
    78     if (nativeForEach && obj.forEach === nativeForEach) {
    79       obj.forEach(iterator, context);
    80     } else if (obj.length === +obj.length) {
    81       for (var i = 0, length = obj.length; i < length; i++) {
    82         if (iterator.call(context, obj[i], i, obj) === breaker) return;
     138  // Handles raw objects in addition to array-likes. Treats all
     139  // sparse array-likes as if they were dense.
     140  _.each = _.forEach = function(obj, iteratee, context) {
     141    iteratee = optimizeCb(iteratee, context);
     142    var i, length;
     143    if (isArrayLike(obj)) {
     144      for (i = 0, length = obj.length; i < length; i++) {
     145        iteratee(obj[i], i, obj);
    83146      }
    84147    } else {
    85148      var keys = _.keys(obj);
    86       for (var i = 0, length = keys.length; i < length; i++) {
    87         if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
     149      for (i = 0, length = keys.length; i < length; i++) {
     150        iteratee(obj[keys[i]], keys[i], obj);
    88151      }
    89152    }
    90153    return obj;
    91154  };
    92155
    93   // Return the results of applying the iterator to each element.
    94   // Delegates to **ECMAScript 5**'s native `map` if available.
    95   _.map = _.collect = function(obj, iterator, context) {
    96     var results = [];
    97     if (obj == null) return results;
    98     if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
    99     each(obj, function(value, index, list) {
    100       results.push(iterator.call(context, value, index, list));
    101     });
     156  // Return the results of applying the iteratee to each element.
     157  _.map = _.collect = function(obj, iteratee, context) {
     158    iteratee = cb(iteratee, context);
     159    var keys = !isArrayLike(obj) && _.keys(obj),
     160        length = (keys || obj).length,
     161        results = Array(length);
     162    for (var index = 0; index < length; index++) {
     163      var currentKey = keys ? keys[index] : index;
     164      results[index] = iteratee(obj[currentKey], currentKey, obj);
     165    }
    102166    return results;
    103167  };
    104168
    105   var reduceError = 'Reduce of empty array with no initial value';
     169  // Create a reducing function iterating left or right.
     170  function createReduce(dir) {
     171    // Optimized iterator function as using arguments.length
     172    // in the main function will deoptimize the, see #1991.
     173    function iterator(obj, iteratee, memo, keys, index, length) {
     174      for (; index >= 0 && index < length; index += dir) {
     175        var currentKey = keys ? keys[index] : index;
     176        memo = iteratee(memo, obj[currentKey], currentKey, obj);
     177      }
     178      return memo;
     179    }
    106180
    107   // **Reduce** builds up a single result from a list of values, aka `inject`,
    108   // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
    109   _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
    110     var initial = arguments.length > 2;
    111     if (obj == null) obj = [];
    112     if (nativeReduce && obj.reduce === nativeReduce) {
    113       if (context) iterator = _.bind(iterator, context);
    114       return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
    115     }
    116     each(obj, function(value, index, list) {
    117       if (!initial) {
    118         memo = value;
    119         initial = true;
    120       } else {
    121         memo = iterator.call(context, memo, value, index, list);
     181    return function(obj, iteratee, memo, context) {
     182      iteratee = optimizeCb(iteratee, context, 4);
     183      var keys = !isArrayLike(obj) && _.keys(obj),
     184          length = (keys || obj).length,
     185          index = dir > 0 ? 0 : length - 1;
     186      // Determine the initial value if none is provided.
     187      if (arguments.length < 3) {
     188        memo = obj[keys ? keys[index] : index];
     189        index += dir;
    122190      }
    123     });
    124     if (!initial) throw new TypeError(reduceError);
    125     return memo;
    126   };
     191      return iterator(obj, iteratee, memo, keys, index, length);
     192    };
     193  }
    127194
     195  // **Reduce** builds up a single result from a list of values, aka `inject`,
     196  // or `foldl`.
     197  _.reduce = _.foldl = _.inject = createReduce(1);
     198
    128199  // The right-associative version of reduce, also known as `foldr`.
    129   // Delegates to **ECMAScript 5**'s native `reduceRight` if available.
    130   _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
    131     var initial = arguments.length > 2;
    132     if (obj == null) obj = [];
    133     if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
    134       if (context) iterator = _.bind(iterator, context);
    135       return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
    136     }
    137     var length = obj.length;
    138     if (length !== +length) {
    139       var keys = _.keys(obj);
    140       length = keys.length;
    141     }
    142     each(obj, function(value, index, list) {
    143       index = keys ? keys[--length] : --length;
    144       if (!initial) {
    145         memo = obj[index];
    146         initial = true;
    147       } else {
    148         memo = iterator.call(context, memo, obj[index], index, list);
    149       }
    150     });
    151     if (!initial) throw new TypeError(reduceError);
    152     return memo;
    153   };
     200  _.reduceRight = _.foldr = createReduce(-1);
    154201
    155202  // Return the first value which passes a truth test. Aliased as `detect`.
    156203  _.find = _.detect = function(obj, predicate, context) {
    157     var result;
    158     any(obj, function(value, index, list) {
    159       if (predicate.call(context, value, index, list)) {
    160         result = value;
    161         return true;
    162       }
    163     });
    164     return result;
     204    var key;
     205    if (isArrayLike(obj)) {
     206      key = _.findIndex(obj, predicate, context);
     207    } else {
     208      key = _.findKey(obj, predicate, context);
     209    }
     210    if (key !== void 0 && key !== -1) return obj[key];
    165211  };
    166212
    167213  // Return all the elements that pass a truth test.
    168   // Delegates to **ECMAScript 5**'s native `filter` if available.
    169214  // Aliased as `select`.
    170215  _.filter = _.select = function(obj, predicate, context) {
    171216    var results = [];
    172     if (obj == null) return results;
    173     if (nativeFilter && obj.filter === nativeFilter) return obj.filter(predicate, context);
    174     each(obj, function(value, index, list) {
    175       if (predicate.call(context, value, index, list)) results.push(value);
     217    predicate = cb(predicate, context);
     218    _.each(obj, function(value, index, list) {
     219      if (predicate(value, index, list)) results.push(value);
    176220    });
    177221    return results;
    178222  };
    179223
    180224  // Return all the elements for which a truth test fails.
    181225  _.reject = function(obj, predicate, context) {
    182     return _.filter(obj, function(value, index, list) {
    183       return !predicate.call(context, value, index, list);
    184     }, context);
     226    return _.filter(obj, _.negate(cb(predicate)), context);
    185227  };
    186228
    187229  // Determine whether all of the elements match a truth test.
    188   // Delegates to **ECMAScript 5**'s native `every` if available.
    189230  // Aliased as `all`.
    190231  _.every = _.all = function(obj, predicate, context) {
    191     predicate || (predicate = _.identity);
    192     var result = true;
    193     if (obj == null) return result;
    194     if (nativeEvery && obj.every === nativeEvery) return obj.every(predicate, context);
    195     each(obj, function(value, index, list) {
    196       if (!(result = result && predicate.call(context, value, index, list))) return breaker;
    197     });
    198     return !!result;
     232    predicate = cb(predicate, context);
     233    var keys = !isArrayLike(obj) && _.keys(obj),
     234        length = (keys || obj).length;
     235    for (var index = 0; index < length; index++) {
     236      var currentKey = keys ? keys[index] : index;
     237      if (!predicate(obj[currentKey], currentKey, obj)) return false;
     238    }
     239    return true;
    199240  };
    200241
    201242  // Determine if at least one element in the object matches a truth test.
    202   // Delegates to **ECMAScript 5**'s native `some` if available.
    203243  // Aliased as `any`.
    204   var any = _.some = _.any = function(obj, predicate, context) {
    205     predicate || (predicate = _.identity);
    206     var result = false;
    207     if (obj == null) return result;
    208     if (nativeSome && obj.some === nativeSome) return obj.some(predicate, context);
    209     each(obj, function(value, index, list) {
    210       if (result || (result = predicate.call(context, value, index, list))) return breaker;
    211     });
    212     return !!result;
     244  _.some = _.any = function(obj, predicate, context) {
     245    predicate = cb(predicate, context);
     246    var keys = !isArrayLike(obj) && _.keys(obj),
     247        length = (keys || obj).length;
     248    for (var index = 0; index < length; index++) {
     249      var currentKey = keys ? keys[index] : index;
     250      if (predicate(obj[currentKey], currentKey, obj)) return true;
     251    }
     252    return false;
    213253  };
    214254
    215255  // Determine if the array or object contains a given value (using `===`).
    216   // Aliased as `include`.
    217   _.contains = _.include = function(obj, target) {
    218     if (obj == null) return false;
    219     if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
    220     return any(obj, function(value) {
    221       return value === target;
    222     });
     256  // Aliased as `includes` and `include`.
     257  _.contains = _.includes = _.include = function(obj, target, fromIndex) {
     258    if (!isArrayLike(obj)) obj = _.values(obj);
     259    return _.indexOf(obj, target, typeof fromIndex == 'number' && fromIndex) >= 0;
    223260  };
    224261
    225262  // Invoke a method (with arguments) on every item in a collection.
     
    227264    var args = slice.call(arguments, 2);
    228265    var isFunc = _.isFunction(method);
    229266    return _.map(obj, function(value) {
    230       return (isFunc ? method : value[method]).apply(value, args);
     267      var func = isFunc ? method : value[method];
     268      return func == null ? func : func.apply(value, args);
    231269    });
    232270  };
    233271
     
    239277  // Convenience version of a common use case of `filter`: selecting only objects
    240278  // containing specific `key:value` pairs.
    241279  _.where = function(obj, attrs) {
    242     return _.filter(obj, _.matches(attrs));
     280    return _.filter(obj, _.matcher(attrs));
    243281  };
    244282
    245283  // Convenience version of a common use case of `find`: getting the first object
    246284  // containing specific `key:value` pairs.
    247285  _.findWhere = function(obj, attrs) {
    248     return _.find(obj, _.matches(attrs));
     286    return _.find(obj, _.matcher(attrs));
    249287  };
    250288
    251   // Return the maximum element or (element-based computation).
    252   // Can't optimize arrays of integers longer than 65,535 elements.
    253   // See [WebKit Bug 80797](https://bugs.webkit.org/show_bug.cgi?id=80797)
    254   _.max = function(obj, iterator, context) {
    255     if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
    256       return Math.max.apply(Math, obj);
     289  // Return the maximum element (or element-based computation).
     290  _.max = function(obj, iteratee, context) {
     291    var result = -Infinity, lastComputed = -Infinity,
     292        value, computed;
     293    if (iteratee == null && obj != null) {
     294      obj = isArrayLike(obj) ? obj : _.values(obj);
     295      for (var i = 0, length = obj.length; i < length; i++) {
     296        value = obj[i];
     297        if (value > result) {
     298          result = value;
     299        }
     300      }
     301    } else {
     302      iteratee = cb(iteratee, context);
     303      _.each(obj, function(value, index, list) {
     304        computed = iteratee(value, index, list);
     305        if (computed > lastComputed || computed === -Infinity && result === -Infinity) {
     306          result = value;
     307          lastComputed = computed;
     308        }
     309      });
    257310    }
    258     var result = -Infinity, lastComputed = -Infinity;
    259     each(obj, function(value, index, list) {
    260       var computed = iterator ? iterator.call(context, value, index, list) : value;
    261       if (computed > lastComputed) {
    262         result = value;
    263         lastComputed = computed;
    264       }
    265     });
    266311    return result;
    267312  };
    268313
    269314  // Return the minimum element (or element-based computation).
    270   _.min = function(obj, iterator, context) {
    271     if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
    272       return Math.min.apply(Math, obj);
     315  _.min = function(obj, iteratee, context) {
     316    var result = Infinity, lastComputed = Infinity,
     317        value, computed;
     318    if (iteratee == null && obj != null) {
     319      obj = isArrayLike(obj) ? obj : _.values(obj);
     320      for (var i = 0, length = obj.length; i < length; i++) {
     321        value = obj[i];
     322        if (value < result) {
     323          result = value;
     324        }
     325      }
     326    } else {
     327      iteratee = cb(iteratee, context);
     328      _.each(obj, function(value, index, list) {
     329        computed = iteratee(value, index, list);
     330        if (computed < lastComputed || computed === Infinity && result === Infinity) {
     331          result = value;
     332          lastComputed = computed;
     333        }
     334      });
    273335    }
    274     var result = Infinity, lastComputed = Infinity;
    275     each(obj, function(value, index, list) {
    276       var computed = iterator ? iterator.call(context, value, index, list) : value;
    277       if (computed < lastComputed) {
    278         result = value;
    279         lastComputed = computed;
    280       }
    281     });
    282336    return result;
    283337  };
    284338
    285   // Shuffle an array, using the modern version of the
     339  // Shuffle a collection, using the modern version of the
    286340  // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
    287341  _.shuffle = function(obj) {
    288     var rand;
    289     var index = 0;
    290     var shuffled = [];
    291     each(obj, function(value) {
    292       rand = _.random(index++);
    293       shuffled[index - 1] = shuffled[rand];
    294       shuffled[rand] = value;
    295     });
     342    var set = isArrayLike(obj) ? obj : _.values(obj);
     343    var length = set.length;
     344    var shuffled = Array(length);
     345    for (var index = 0, rand; index < length; index++) {
     346      rand = _.random(0, index);
     347      if (rand !== index) shuffled[index] = shuffled[rand];
     348      shuffled[rand] = set[index];
     349    }
    296350    return shuffled;
    297351  };
    298352
     
    301355  // The internal `guard` argument allows it to work with `map`.
    302356  _.sample = function(obj, n, guard) {
    303357    if (n == null || guard) {
    304       if (obj.length !== +obj.length) obj = _.values(obj);
     358      if (!isArrayLike(obj)) obj = _.values(obj);
    305359      return obj[_.random(obj.length - 1)];
    306360    }
    307361    return _.shuffle(obj).slice(0, Math.max(0, n));
    308362  };
    309363
    310   // An internal function to generate lookup iterators.
    311   var lookupIterator = function(value) {
    312     if (value == null) return _.identity;
    313     if (_.isFunction(value)) return value;
    314     return _.property(value);
    315   };
    316 
    317   // Sort the object's values by a criterion produced by an iterator.
    318   _.sortBy = function(obj, iterator, context) {
    319     iterator = lookupIterator(iterator);
     364  // Sort the object's values by a criterion produced by an iteratee.
     365  _.sortBy = function(obj, iteratee, context) {
     366    iteratee = cb(iteratee, context);
    320367    return _.pluck(_.map(obj, function(value, index, list) {
    321368      return {
    322369        value: value,
    323370        index: index,
    324         criteria: iterator.call(context, value, index, list)
     371        criteria: iteratee(value, index, list)
    325372      };
    326373    }).sort(function(left, right) {
    327374      var a = left.criteria;
     
    336383
    337384  // An internal function used for aggregate "group by" operations.
    338385  var group = function(behavior) {
    339     return function(obj, iterator, context) {
     386    return function(obj, iteratee, context) {
    340387      var result = {};
    341       iterator = lookupIterator(iterator);
    342       each(obj, function(value, index) {
    343         var key = iterator.call(context, value, index, obj);
    344         behavior(result, key, value);
     388      iteratee = cb(iteratee, context);
     389      _.each(obj, function(value, index) {
     390        var key = iteratee(value, index, obj);
     391        behavior(result, value, key);
    345392      });
    346393      return result;
    347394    };
     
    349396
    350397  // Groups the object's values by a criterion. Pass either a string attribute
    351398  // to group by, or a function that returns the criterion.
    352   _.groupBy = group(function(result, key, value) {
    353     _.has(result, key) ? result[key].push(value) : result[key] = [value];
     399  _.groupBy = group(function(result, value, key) {
     400    if (_.has(result, key)) result[key].push(value); else result[key] = [value];
    354401  });
    355402
    356403  // Indexes the object's values by a criterion, similar to `groupBy`, but for
    357404  // when you know that your index values will be unique.
    358   _.indexBy = group(function(result, key, value) {
     405  _.indexBy = group(function(result, value, key) {
    359406    result[key] = value;
    360407  });
    361408
    362409  // Counts instances of an object that group by a certain criterion. Pass
    363410  // either a string attribute to count by, or a function that returns the
    364411  // criterion.
    365   _.countBy = group(function(result, key) {
    366     _.has(result, key) ? result[key]++ : result[key] = 1;
     412  _.countBy = group(function(result, value, key) {
     413    if (_.has(result, key)) result[key]++; else result[key] = 1;
    367414  });
    368415
    369   // Use a comparator function to figure out the smallest index at which
    370   // an object should be inserted so as to maintain order. Uses binary search.
    371   _.sortedIndex = function(array, obj, iterator, context) {
    372     iterator = lookupIterator(iterator);
    373     var value = iterator.call(context, obj);
    374     var low = 0, high = array.length;
    375     while (low < high) {
    376       var mid = (low + high) >>> 1;
    377       iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid;
    378     }
    379     return low;
    380   };
    381 
    382416  // Safely create a real, live array from anything iterable.
    383417  _.toArray = function(obj) {
    384418    if (!obj) return [];
    385419    if (_.isArray(obj)) return slice.call(obj);
    386     if (obj.length === +obj.length) return _.map(obj, _.identity);
     420    if (isArrayLike(obj)) return _.map(obj, _.identity);
    387421    return _.values(obj);
    388422  };
    389423
    390424  // Return the number of elements in an object.
    391425  _.size = function(obj) {
    392426    if (obj == null) return 0;
    393     return (obj.length === +obj.length) ? obj.length : _.keys(obj).length;
     427    return isArrayLike(obj) ? obj.length : _.keys(obj).length;
    394428  };
    395429
     430  // Split a collection into two arrays: one whose elements all satisfy the given
     431  // predicate, and one whose elements all do not satisfy the predicate.
     432  _.partition = function(obj, predicate, context) {
     433    predicate = cb(predicate, context);
     434    var pass = [], fail = [];
     435    _.each(obj, function(value, key, obj) {
     436      (predicate(value, key, obj) ? pass : fail).push(value);
     437    });
     438    return [pass, fail];
     439  };
     440
    396441  // Array Functions
    397442  // ---------------
    398443
     
    401446  // allows it to work with `_.map`.
    402447  _.first = _.head = _.take = function(array, n, guard) {
    403448    if (array == null) return void 0;
    404     if ((n == null) || guard) return array[0];
    405     if (n < 0) return [];
    406     return slice.call(array, 0, n);
     449    if (n == null || guard) return array[0];
     450    return _.initial(array, array.length - n);
    407451  };
    408452
    409453  // Returns everything but the last entry of the array. Especially useful on
    410454  // the arguments object. Passing **n** will return all the values in
    411   // the array, excluding the last N. The **guard** check allows it to work with
    412   // `_.map`.
     455  // the array, excluding the last N.
    413456  _.initial = function(array, n, guard) {
    414     return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
     457    return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
    415458  };
    416459
    417460  // Get the last element of an array. Passing **n** will return the last N
    418   // values in the array. The **guard** check allows it to work with `_.map`.
     461  // values in the array.
    419462  _.last = function(array, n, guard) {
    420463    if (array == null) return void 0;
    421     if ((n == null) || guard) return array[array.length - 1];
    422     return slice.call(array, Math.max(array.length - n, 0));
     464    if (n == null || guard) return array[array.length - 1];
     465    return _.rest(array, Math.max(0, array.length - n));
    423466  };
    424467
    425468  // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
    426469  // Especially useful on the arguments object. Passing an **n** will return
    427   // the rest N values in the array. The **guard**
    428   // check allows it to work with `_.map`.
     470  // the rest N values in the array.
    429471  _.rest = _.tail = _.drop = function(array, n, guard) {
    430     return slice.call(array, (n == null) || guard ? 1 : n);
     472    return slice.call(array, n == null || guard ? 1 : n);
    431473  };
    432474
    433475  // Trim out all falsy values from an array.
     
    436478  };
    437479
    438480  // Internal implementation of a recursive `flatten` function.
    439   var flatten = function(input, shallow, output) {
    440     if (shallow && _.every(input, _.isArray)) {
    441       return concat.apply(output, input);
     481  var flatten = function(input, shallow, strict, startIndex) {
     482    var output = [], idx = 0;
     483    for (var i = startIndex || 0, length = input && input.length; i < length; i++) {
     484      var value = input[i];
     485      if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) {
     486        //flatten current level of array or arguments object
     487        if (!shallow) value = flatten(value, shallow, strict);
     488        var j = 0, len = value.length;
     489        output.length += len;
     490        while (j < len) {
     491          output[idx++] = value[j++];
     492        }
     493      } else if (!strict) {
     494        output[idx++] = value;
     495      }
    442496    }
    443     each(input, function(value) {
    444       if (_.isArray(value) || _.isArguments(value)) {
    445         shallow ? push.apply(output, value) : flatten(value, shallow, output);
    446       } else {
    447         output.push(value);
    448       }
    449     });
    450497    return output;
    451498  };
    452499
    453500  // Flatten out an array, either recursively (by default), or just one level.
    454501  _.flatten = function(array, shallow) {
    455     return flatten(array, shallow, []);
     502    return flatten(array, shallow, false);
    456503  };
    457504
    458505  // Return a version of the array that does not contain the specified value(s).
     
    460507    return _.difference(array, slice.call(arguments, 1));
    461508  };
    462509
    463   // Split an array into two arrays: one whose elements all satisfy the given
    464   // predicate, and one whose elements all do not satisfy the predicate.
    465   _.partition = function(array, predicate) {
    466     var pass = [], fail = [];
    467     each(array, function(elem) {
    468       (predicate(elem) ? pass : fail).push(elem);
    469     });
    470     return [pass, fail];
    471   };
    472 
    473510  // Produce a duplicate-free version of the array. If the array has already
    474511  // been sorted, you have the option of using a faster algorithm.
    475512  // Aliased as `unique`.
    476   _.uniq = _.unique = function(array, isSorted, iterator, context) {
    477     if (_.isFunction(isSorted)) {
    478       context = iterator;
    479       iterator = isSorted;
     513  _.uniq = _.unique = function(array, isSorted, iteratee, context) {
     514    if (array == null) return [];
     515    if (!_.isBoolean(isSorted)) {
     516      context = iteratee;
     517      iteratee = isSorted;
    480518      isSorted = false;
    481519    }
    482     var initial = iterator ? _.map(array, iterator, context) : array;
    483     var results = [];
     520    if (iteratee != null) iteratee = cb(iteratee, context);
     521    var result = [];
    484522    var seen = [];
    485     each(initial, function(value, index) {
    486       if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) {
    487         seen.push(value);
    488         results.push(array[index]);
     523    for (var i = 0, length = array.length; i < length; i++) {
     524      var value = array[i],
     525          computed = iteratee ? iteratee(value, i, array) : value;
     526      if (isSorted) {
     527        if (!i || seen !== computed) result.push(value);
     528        seen = computed;
     529      } else if (iteratee) {
     530        if (!_.contains(seen, computed)) {
     531          seen.push(computed);
     532          result.push(value);
     533        }
     534      } else if (!_.contains(result, value)) {
     535        result.push(value);
    489536      }
    490     });
    491     return results;
     537    }
     538    return result;
    492539  };
    493540
    494541  // Produce an array that contains the union: each distinct element from all of
    495542  // the passed-in arrays.
    496543  _.union = function() {
    497     return _.uniq(_.flatten(arguments, true));
     544    return _.uniq(flatten(arguments, true, true));
    498545  };
    499546
    500547  // Produce an array that contains every item shared between all the
    501548  // passed-in arrays.
    502549  _.intersection = function(array) {
    503     var rest = slice.call(arguments, 1);
    504     return _.filter(_.uniq(array), function(item) {
    505       return _.every(rest, function(other) {
    506         return _.contains(other, item);
    507       });
    508     });
     550    if (array == null) return [];
     551    var result = [];
     552    var argsLength = arguments.length;
     553    for (var i = 0, length = array.length; i < length; i++) {
     554      var item = array[i];
     555      if (_.contains(result, item)) continue;
     556      for (var j = 1; j < argsLength; j++) {
     557        if (!_.contains(arguments[j], item)) break;
     558      }
     559      if (j === argsLength) result.push(item);
     560    }
     561    return result;
    509562  };
    510563
    511564  // Take the difference between one array and a number of other arrays.
    512565  // Only the elements present in just the first array will remain.
    513566  _.difference = function(array) {
    514     var rest = concat.apply(ArrayProto, slice.call(arguments, 1));
    515     return _.filter(array, function(value){ return !_.contains(rest, value); });
     567    var rest = flatten(arguments, true, true, 1);
     568    return _.filter(array, function(value){
     569      return !_.contains(rest, value);
     570    });
    516571  };
    517572
    518573  // Zip together multiple lists into a single array -- elements that share
    519574  // an index go together.
    520575  _.zip = function() {
    521     var length = _.max(_.pluck(arguments, 'length').concat(0));
    522     var results = new Array(length);
    523     for (var i = 0; i < length; i++) {
    524       results[i] = _.pluck(arguments, '' + i);
     576    return _.unzip(arguments);
     577  };
     578
     579  // Complement of _.zip. Unzip accepts an array of arrays and groups
     580  // each array's elements on shared indices
     581  _.unzip = function(array) {
     582    var length = array && _.max(array, 'length').length || 0;
     583    var result = Array(length);
     584
     585    for (var index = 0; index < length; index++) {
     586      result[index] = _.pluck(array, index);
    525587    }
    526     return results;
     588    return result;
    527589  };
    528590
    529591  // Converts lists into objects. Pass either a single array of `[key, value]`
    530592  // pairs, or two parallel arrays of the same length -- one of keys, and one of
    531593  // the corresponding values.
    532594  _.object = function(list, values) {
    533     if (list == null) return {};
    534595    var result = {};
    535     for (var i = 0, length = list.length; i < length; i++) {
     596    for (var i = 0, length = list && list.length; i < length; i++) {
    536597      if (values) {
    537598        result[list[i]] = values[i];
    538599      } else {
     
    542603    return result;
    543604  };
    544605
    545   // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
    546   // we need this function. Return the position of the first occurrence of an
    547   // item in an array, or -1 if the item is not included in the array.
    548   // Delegates to **ECMAScript 5**'s native `indexOf` if available.
     606  // Return the position of the first occurrence of an item in an array,
     607  // or -1 if the item is not included in the array.
    549608  // If the array is large and already in sort order, pass `true`
    550609  // for **isSorted** to use binary search.
    551610  _.indexOf = function(array, item, isSorted) {
    552     if (array == null) return -1;
    553     var i = 0, length = array.length;
    554     if (isSorted) {
    555       if (typeof isSorted == 'number') {
    556         i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted);
    557       } else {
    558         i = _.sortedIndex(array, item);
    559         return array[i] === item ? i : -1;
    560       }
     611    var i = 0, length = array && array.length;
     612    if (typeof isSorted == 'number') {
     613      i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted;
     614    } else if (isSorted && length) {
     615      i = _.sortedIndex(array, item);
     616      return array[i] === item ? i : -1;
    561617    }
    562     if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
     618    if (item !== item) {
     619      return _.findIndex(slice.call(array, i), _.isNaN);
     620    }
    563621    for (; i < length; i++) if (array[i] === item) return i;
    564622    return -1;
    565623  };
    566624
    567   // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
    568625  _.lastIndexOf = function(array, item, from) {
    569     if (array == null) return -1;
    570     var hasIndex = from != null;
    571     if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) {
    572       return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item);
     626    var idx = array ? array.length : 0;
     627    if (typeof from == 'number') {
     628      idx = from < 0 ? idx + from + 1 : Math.min(idx, from + 1);
    573629    }
    574     var i = (hasIndex ? from : array.length);
    575     while (i--) if (array[i] === item) return i;
     630    if (item !== item) {
     631      return _.findLastIndex(slice.call(array, 0, idx), _.isNaN);
     632    }
     633    while (--idx >= 0) if (array[idx] === item) return idx;
    576634    return -1;
    577635  };
    578636
     637  // Generator function to create the findIndex and findLastIndex functions
     638  function createIndexFinder(dir) {
     639    return function(array, predicate, context) {
     640      predicate = cb(predicate, context);
     641      var length = array != null && array.length;
     642      var index = dir > 0 ? 0 : length - 1;
     643      for (; index >= 0 && index < length; index += dir) {
     644        if (predicate(array[index], index, array)) return index;
     645      }
     646      return -1;
     647    };
     648  }
     649
     650  // Returns the first index on an array-like that passes a predicate test
     651  _.findIndex = createIndexFinder(1);
     652
     653  _.findLastIndex = createIndexFinder(-1);
     654
     655  // Use a comparator function to figure out the smallest index at which
     656  // an object should be inserted so as to maintain order. Uses binary search.
     657  _.sortedIndex = function(array, obj, iteratee, context) {
     658    iteratee = cb(iteratee, context, 1);
     659    var value = iteratee(obj);
     660    var low = 0, high = array.length;
     661    while (low < high) {
     662      var mid = Math.floor((low + high) / 2);
     663      if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
     664    }
     665    return low;
     666  };
     667
    579668  // Generate an integer Array containing an arithmetic progression. A port of
    580669  // the native Python `range()` function. See
    581670  // [the Python documentation](http://docs.python.org/library/functions.html#range).
     
    584673      stop = start || 0;
    585674      start = 0;
    586675    }
    587     step = arguments[2] || 1;
     676    step = step || 1;
    588677
    589678    var length = Math.max(Math.ceil((stop - start) / step), 0);
    590     var idx = 0;
    591     var range = new Array(length);
     679    var range = Array(length);
    592680
    593     while(idx < length) {
    594       range[idx++] = start;
    595       start += step;
     681    for (var idx = 0; idx < length; idx++, start += step) {
     682      range[idx] = start;
    596683    }
    597684
    598685    return range;
     
    601688  // Function (ahem) Functions
    602689  // ------------------
    603690
    604   // Reusable constructor function for prototype setting.
    605   var ctor = function(){};
     691  // Determines whether to execute a function as a constructor
     692  // or a normal function with the provided arguments
     693  var executeBound = function(sourceFunc, boundFunc, context, callingContext, args) {
     694    if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
     695    var self = baseCreate(sourceFunc.prototype);
     696    var result = sourceFunc.apply(self, args);
     697    if (_.isObject(result)) return result;
     698    return self;
     699  };
    606700
    607701  // Create a function bound to a given object (assigning `this`, and arguments,
    608702  // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
    609703  // available.
    610704  _.bind = function(func, context) {
    611     var args, bound;
    612705    if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
    613     if (!_.isFunction(func)) throw new TypeError;
    614     args = slice.call(arguments, 2);
    615     return bound = function() {
    616       if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
    617       ctor.prototype = func.prototype;
    618       var self = new ctor;
    619       ctor.prototype = null;
    620       var result = func.apply(self, args.concat(slice.call(arguments)));
    621       if (Object(result) === result) return result;
    622       return self;
     706    if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function');
     707    var args = slice.call(arguments, 2);
     708    var bound = function() {
     709      return executeBound(func, bound, context, this, args.concat(slice.call(arguments)));
    623710    };
     711    return bound;
    624712  };
    625713
    626714  // Partially apply a function by creating a version that has had some of its
     
    628716  // as a placeholder, allowing any combination of arguments to be pre-filled.
    629717  _.partial = function(func) {
    630718    var boundArgs = slice.call(arguments, 1);
    631     return function() {
    632       var position = 0;
    633       var args = boundArgs.slice();
    634       for (var i = 0, length = args.length; i < length; i++) {
    635         if (args[i] === _) args[i] = arguments[position++];
     719    var bound = function() {
     720      var position = 0, length = boundArgs.length;
     721      var args = Array(length);
     722      for (var i = 0; i < length; i++) {
     723        args[i] = boundArgs[i] === _ ? arguments[position++] : boundArgs[i];
    636724      }
    637725      while (position < arguments.length) args.push(arguments[position++]);
    638       return func.apply(this, args);
     726      return executeBound(func, bound, this, this, args);
    639727    };
     728    return bound;
    640729  };
    641730
    642731  // Bind a number of an object's methods to that object. Remaining arguments
    643732  // are the method names to be bound. Useful for ensuring that all callbacks
    644733  // defined on an object belong to it.
    645734  _.bindAll = function(obj) {
    646     var funcs = slice.call(arguments, 1);
    647     if (funcs.length === 0) throw new Error('bindAll must be passed function names');
    648     each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
     735    var i, length = arguments.length, key;
     736    if (length <= 1) throw new Error('bindAll must be passed function names');
     737    for (i = 1; i < length; i++) {
     738      key = arguments[i];
     739      obj[key] = _.bind(obj[key], obj);
     740    }
    649741    return obj;
    650742  };
    651743
    652744  // Memoize an expensive function by storing its results.
    653745  _.memoize = function(func, hasher) {
    654     var memo = {};
    655     hasher || (hasher = _.identity);
    656     return function() {
    657       var key = hasher.apply(this, arguments);
    658       return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
     746    var memoize = function(key) {
     747      var cache = memoize.cache;
     748      var address = '' + (hasher ? hasher.apply(this, arguments) : key);
     749      if (!_.has(cache, address)) cache[address] = func.apply(this, arguments);
     750      return cache[address];
    659751    };
     752    memoize.cache = {};
     753    return memoize;
    660754  };
    661755
    662756  // Delays a function for the given number of milliseconds, and then calls
    663757  // it with the arguments supplied.
    664758  _.delay = function(func, wait) {
    665759    var args = slice.call(arguments, 2);
    666     return setTimeout(function(){ return func.apply(null, args); }, wait);
     760    return setTimeout(function(){
     761      return func.apply(null, args);
     762    }, wait);
    667763  };
    668764
    669765  // Defers a function, scheduling it to run after the current call stack has
    670766  // cleared.
    671   _.defer = function(func) {
    672     return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
    673   };
     767  _.defer = _.partial(_.delay, _, 1);
    674768
    675769  // Returns a function, that, when invoked, will only be triggered at most once
    676770  // during a given window of time. Normally, the throttled function will run
     
    681775    var context, args, result;
    682776    var timeout = null;
    683777    var previous = 0;
    684     options || (options = {});
     778    if (!options) options = {};
    685779    var later = function() {
    686780      previous = options.leading === false ? 0 : _.now();
    687781      timeout = null;
    688782      result = func.apply(context, args);
    689       context = args = null;
     783      if (!timeout) context = args = null;
    690784    };
    691785    return function() {
    692786      var now = _.now();
     
    694788      var remaining = wait - (now - previous);
    695789      context = this;
    696790      args = arguments;
    697       if (remaining <= 0) {
    698         clearTimeout(timeout);
    699         timeout = null;
     791      if (remaining <= 0 || remaining > wait) {
     792        if (timeout) {
     793          clearTimeout(timeout);
     794          timeout = null;
     795        }
    700796        previous = now;
    701797        result = func.apply(context, args);
    702         context = args = null;
     798        if (!timeout) context = args = null;
    703799      } else if (!timeout && options.trailing !== false) {
    704800        timeout = setTimeout(later, remaining);
    705801      }
     
    716812
    717813    var later = function() {
    718814      var last = _.now() - timestamp;
    719       if (last < wait) {
     815
     816      if (last < wait && last >= 0) {
    720817        timeout = setTimeout(later, wait - last);
    721818      } else {
    722819        timeout = null;
    723820        if (!immediate) {
    724821          result = func.apply(context, args);
    725           context = args = null;
     822          if (!timeout) context = args = null;
    726823        }
    727824      }
    728825    };
     
    732829      args = arguments;
    733830      timestamp = _.now();
    734831      var callNow = immediate && !timeout;
    735       if (!timeout) {
    736         timeout = setTimeout(later, wait);
    737       }
     832      if (!timeout) timeout = setTimeout(later, wait);
    738833      if (callNow) {
    739834        result = func.apply(context, args);
    740835        context = args = null;
     
    744839    };
    745840  };
    746841
    747   // Returns a function that will be executed at most one time, no matter how
    748   // often you call it. Useful for lazy initialization.
    749   _.once = function(func) {
    750     var ran = false, memo;
    751     return function() {
    752       if (ran) return memo;
    753       ran = true;
    754       memo = func.apply(this, arguments);
    755       func = null;
    756       return memo;
    757     };
    758   };
    759 
    760842  // Returns the first function passed as an argument to the second,
    761843  // allowing you to adjust arguments, run code before and after, and
    762844  // conditionally execute the original function.
     
    764846    return _.partial(wrapper, func);
    765847  };
    766848
     849  // Returns a negated version of the passed-in predicate.
     850  _.negate = function(predicate) {
     851    return function() {
     852      return !predicate.apply(this, arguments);
     853    };
     854  };
     855
    767856  // Returns a function that is the composition of a list of functions, each
    768857  // consuming the return value of the function that follows.
    769858  _.compose = function() {
    770     var funcs = arguments;
     859    var args = arguments;
     860    var start = args.length - 1;
    771861    return function() {
    772       var args = arguments;
    773       for (var i = funcs.length - 1; i >= 0; i--) {
    774         args = [funcs[i].apply(this, args)];
    775       }
    776       return args[0];
     862      var i = start;
     863      var result = args[start].apply(this, arguments);
     864      while (i--) result = args[i].call(this, result);
     865      return result;
    777866    };
    778867  };
    779868
    780   // Returns a function that will only be executed after being called N times.
     869  // Returns a function that will only be executed on and after the Nth call.
    781870  _.after = function(times, func) {
    782871    return function() {
    783872      if (--times < 1) {
     
    786875    };
    787876  };
    788877
     878  // Returns a function that will only be executed up to (but not including) the Nth call.
     879  _.before = function(times, func) {
     880    var memo;
     881    return function() {
     882      if (--times > 0) {
     883        memo = func.apply(this, arguments);
     884      }
     885      if (times <= 1) func = null;
     886      return memo;
     887    };
     888  };
     889
     890  // Returns a function that will be executed at most one time, no matter how
     891  // often you call it. Useful for lazy initialization.
     892  _.once = _.partial(_.before, 2);
     893
    789894  // Object Functions
    790895  // ----------------
    791896
    792   // Retrieve the names of an object's properties.
     897  // Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
     898  var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
     899  var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
     900                      'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
     901
     902  function collectNonEnumProps(obj, keys) {
     903    var nonEnumIdx = nonEnumerableProps.length;
     904    var constructor = obj.constructor;
     905    var proto = (_.isFunction(constructor) && constructor.prototype) || ObjProto;
     906
     907    // Constructor is a special case.
     908    var prop = 'constructor';
     909    if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop);
     910
     911    while (nonEnumIdx--) {
     912      prop = nonEnumerableProps[nonEnumIdx];
     913      if (prop in obj && obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
     914        keys.push(prop);
     915      }
     916    }
     917  }
     918
     919  // Retrieve the names of an object's own properties.
    793920  // Delegates to **ECMAScript 5**'s native `Object.keys`
    794921  _.keys = function(obj) {
    795922    if (!_.isObject(obj)) return [];
    796923    if (nativeKeys) return nativeKeys(obj);
    797924    var keys = [];
    798925    for (var key in obj) if (_.has(obj, key)) keys.push(key);
     926    // Ahem, IE < 9.
     927    if (hasEnumBug) collectNonEnumProps(obj, keys);
    799928    return keys;
    800929  };
    801930
     931  // Retrieve all the property names of an object.
     932  _.allKeys = function(obj) {
     933    if (!_.isObject(obj)) return [];
     934    var keys = [];
     935    for (var key in obj) keys.push(key);
     936    // Ahem, IE < 9.
     937    if (hasEnumBug) collectNonEnumProps(obj, keys);
     938    return keys;
     939  };
     940
    802941  // Retrieve the values of an object's properties.
    803942  _.values = function(obj) {
    804943    var keys = _.keys(obj);
    805944    var length = keys.length;
    806     var values = new Array(length);
     945    var values = Array(length);
    807946    for (var i = 0; i < length; i++) {
    808947      values[i] = obj[keys[i]];
    809948    }
    810949    return values;
    811950  };
    812951
     952  // Returns the results of applying the iteratee to each element of the object
     953  // In contrast to _.map it returns an object
     954  _.mapObject = function(obj, iteratee, context) {
     955    iteratee = cb(iteratee, context);
     956    var keys =  _.keys(obj),
     957          length = keys.length,
     958          results = {},
     959          currentKey;
     960      for (var index = 0; index < length; index++) {
     961        currentKey = keys[index];
     962        results[currentKey] = iteratee(obj[currentKey], currentKey, obj);
     963      }
     964      return results;
     965  };
     966
    813967  // Convert an object into a list of `[key, value]` pairs.
    814968  _.pairs = function(obj) {
    815969    var keys = _.keys(obj);
    816970    var length = keys.length;
    817     var pairs = new Array(length);
     971    var pairs = Array(length);
    818972    for (var i = 0; i < length; i++) {
    819973      pairs[i] = [keys[i], obj[keys[i]]];
    820974    }
     
    842996  };
    843997
    844998  // Extend a given object with all the properties in passed-in object(s).
    845   _.extend = function(obj) {
    846     each(slice.call(arguments, 1), function(source) {
    847       if (source) {
    848         for (var prop in source) {
    849           obj[prop] = source[prop];
    850         }
    851       }
    852     });
    853     return obj;
     999  _.extend = createAssigner(_.allKeys);
     1000
     1001  // Assigns a given object with all the own properties in the passed-in object(s)
     1002  // (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
     1003  _.extendOwn = _.assign = createAssigner(_.keys);
     1004
     1005  // Returns the first key on an object that passes a predicate test
     1006  _.findKey = function(obj, predicate, context) {
     1007    predicate = cb(predicate, context);
     1008    var keys = _.keys(obj), key;
     1009    for (var i = 0, length = keys.length; i < length; i++) {
     1010      key = keys[i];
     1011      if (predicate(obj[key], key, obj)) return key;
     1012    }
    8541013  };
    8551014
    8561015  // Return a copy of the object only containing the whitelisted properties.
    857   _.pick = function(obj) {
    858     var copy = {};
    859     var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
    860     each(keys, function(key) {
    861       if (key in obj) copy[key] = obj[key];
    862     });
    863     return copy;
     1016  _.pick = function(object, oiteratee, context) {
     1017    var result = {}, obj = object, iteratee, keys;
     1018    if (obj == null) return result;
     1019    if (_.isFunction(oiteratee)) {
     1020      keys = _.allKeys(obj);
     1021      iteratee = optimizeCb(oiteratee, context);
     1022    } else {
     1023      keys = flatten(arguments, false, false, 1);
     1024      iteratee = function(value, key, obj) { return key in obj; };
     1025      obj = Object(obj);
     1026    }
     1027    for (var i = 0, length = keys.length; i < length; i++) {
     1028      var key = keys[i];
     1029      var value = obj[key];
     1030      if (iteratee(value, key, obj)) result[key] = value;
     1031    }
     1032    return result;
    8641033  };
    8651034
    8661035   // Return a copy of the object without the blacklisted properties.
    867   _.omit = function(obj) {
    868     var copy = {};
    869     var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
    870     for (var key in obj) {
    871       if (!_.contains(keys, key)) copy[key] = obj[key];
     1036  _.omit = function(obj, iteratee, context) {
     1037    if (_.isFunction(iteratee)) {
     1038      iteratee = _.negate(iteratee);
     1039    } else {
     1040      var keys = _.map(flatten(arguments, false, false, 1), String);
     1041      iteratee = function(value, key) {
     1042        return !_.contains(keys, key);
     1043      };
    8721044    }
    873     return copy;
     1045    return _.pick(obj, iteratee, context);
    8741046  };
    8751047
    8761048  // Fill in a given object with default properties.
    877   _.defaults = function(obj) {
    878     each(slice.call(arguments, 1), function(source) {
    879       if (source) {
    880         for (var prop in source) {
    881           if (obj[prop] === void 0) obj[prop] = source[prop];
    882         }
    883       }
    884     });
    885     return obj;
    886   };
     1049  _.defaults = createAssigner(_.allKeys, true);
    8871050
    8881051  // Create a (shallow-cloned) duplicate of an object.
    8891052  _.clone = function(obj) {
     
    8991062    return obj;
    9001063  };
    9011064
     1065  // Returns whether an object has a given set of `key:value` pairs.
     1066  _.isMatch = function(object, attrs) {
     1067    var keys = _.keys(attrs), length = keys.length;
     1068    if (object == null) return !length;
     1069    var obj = Object(object);
     1070    for (var i = 0; i < length; i++) {
     1071      var key = keys[i];
     1072      if (attrs[key] !== obj[key] || !(key in obj)) return false;
     1073    }
     1074    return true;
     1075  };
     1076
     1077
    9021078  // Internal recursive comparison function for `isEqual`.
    9031079  var eq = function(a, b, aStack, bStack) {
    9041080    // Identical objects are equal. `0 === -0`, but they aren't identical.
    9051081    // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
    906     if (a === b) return a !== 0 || 1 / a == 1 / b;
     1082    if (a === b) return a !== 0 || 1 / a === 1 / b;
    9071083    // A strict comparison is necessary because `null == undefined`.
    9081084    if (a == null || b == null) return a === b;
    9091085    // Unwrap any wrapped objects.
     
    9111087    if (b instanceof _) b = b._wrapped;
    9121088    // Compare `[[Class]]` names.
    9131089    var className = toString.call(a);
    914     if (className != toString.call(b)) return false;
     1090    if (className !== toString.call(b)) return false;
    9151091    switch (className) {
    916       // Strings, numbers, dates, and booleans are compared by value.
     1092      // Strings, numbers, regular expressions, dates, and booleans are compared by value.
     1093      case '[object RegExp]':
     1094      // RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
    9171095      case '[object String]':
    9181096        // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
    9191097        // equivalent to `new String("5")`.
    920         return a == String(b);
     1098        return '' + a === '' + b;
    9211099      case '[object Number]':
    922         // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
    923         // other numeric values.
    924         return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
     1100        // `NaN`s are equivalent, but non-reflexive.
     1101        // Object(NaN) is equivalent to NaN
     1102        if (+a !== +a) return +b !== +b;
     1103        // An `egal` comparison is performed for other numeric values.
     1104        return +a === 0 ? 1 / +a === 1 / b : +a === +b;
    9251105      case '[object Date]':
    9261106      case '[object Boolean]':
    9271107        // Coerce dates and booleans to numeric primitive values. Dates are compared by their
    9281108        // millisecond representations. Note that invalid dates with millisecond representations
    9291109        // of `NaN` are not equivalent.
    930         return +a == +b;
    931       // RegExps are compared by their source patterns and flags.
    932       case '[object RegExp]':
    933         return a.source == b.source &&
    934                a.global == b.global &&
    935                a.multiline == b.multiline &&
    936                a.ignoreCase == b.ignoreCase;
     1110        return +a === +b;
    9371111    }
    938     if (typeof a != 'object' || typeof b != 'object') return false;
     1112
     1113    var areArrays = className === '[object Array]';
     1114    if (!areArrays) {
     1115      if (typeof a != 'object' || typeof b != 'object') return false;
     1116
     1117      // Objects with different constructors are not equivalent, but `Object`s or `Array`s
     1118      // from different frames are.
     1119      var aCtor = a.constructor, bCtor = b.constructor;
     1120      if (aCtor !== bCtor && !(_.isFunction(aCtor) && aCtor instanceof aCtor &&
     1121                               _.isFunction(bCtor) && bCtor instanceof bCtor)
     1122                          && ('constructor' in a && 'constructor' in b)) {
     1123        return false;
     1124      }
     1125    }
    9391126    // Assume equality for cyclic structures. The algorithm for detecting cyclic
    9401127    // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
     1128
     1129    // Initializing stack of traversed objects.
     1130    // It's done here since we only need them for objects and arrays comparison.
     1131    aStack = aStack || [];
     1132    bStack = bStack || [];
    9411133    var length = aStack.length;
    9421134    while (length--) {
    9431135      // Linear search. Performance is inversely proportional to the number of
    9441136      // unique nested structures.
    945       if (aStack[length] == a) return bStack[length] == b;
     1137      if (aStack[length] === a) return bStack[length] === b;
    9461138    }
    947     // Objects with different constructors are not equivalent, but `Object`s
    948     // from different frames are.
    949     var aCtor = a.constructor, bCtor = b.constructor;
    950     if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
    951                              _.isFunction(bCtor) && (bCtor instanceof bCtor))
    952                         && ('constructor' in a && 'constructor' in b)) {
    953       return false;
    954     }
     1139
    9551140    // Add the first object to the stack of traversed objects.
    9561141    aStack.push(a);
    9571142    bStack.push(b);
    958     var size = 0, result = true;
     1143
    9591144    // Recursively compare objects and arrays.
    960     if (className == '[object Array]') {
     1145    if (areArrays) {
    9611146      // Compare array lengths to determine if a deep comparison is necessary.
    962       size = a.length;
    963       result = size == b.length;
    964       if (result) {
    965         // Deep compare the contents, ignoring non-numeric properties.
    966         while (size--) {
    967           if (!(result = eq(a[size], b[size], aStack, bStack))) break;
    968         }
     1147      length = a.length;
     1148      if (length !== b.length) return false;
     1149      // Deep compare the contents, ignoring non-numeric properties.
     1150      while (length--) {
     1151        if (!eq(a[length], b[length], aStack, bStack)) return false;
    9691152      }
    9701153    } else {
    9711154      // Deep compare objects.
    972       for (var key in a) {
    973         if (_.has(a, key)) {
    974           // Count the expected number of properties.
    975           size++;
    976           // Deep compare each member.
    977           if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
    978         }
     1155      var keys = _.keys(a), key;
     1156      length = keys.length;
     1157      // Ensure that both objects contain the same number of properties before comparing deep equality.
     1158      if (_.keys(b).length !== length) return false;
     1159      while (length--) {
     1160        // Deep compare each member
     1161        key = keys[length];
     1162        if (!(_.has(b, key) && eq(a[key], b[key], aStack, bStack))) return false;
    9791163      }
    980       // Ensure that both objects contain the same number of properties.
    981       if (result) {
    982         for (key in b) {
    983           if (_.has(b, key) && !(size--)) break;
    984         }
    985         result = !size;
    986       }
    9871164    }
    9881165    // Remove the first object from the stack of traversed objects.
    9891166    aStack.pop();
    9901167    bStack.pop();
    991     return result;
     1168    return true;
    9921169  };
    9931170
    9941171  // Perform a deep comparison to check if two objects are equal.
    9951172  _.isEqual = function(a, b) {
    996     return eq(a, b, [], []);
     1173    return eq(a, b);
    9971174  };
    9981175
    9991176  // Is a given array, string, or object empty?
    10001177  // An "empty" object has no enumerable own-properties.
    10011178  _.isEmpty = function(obj) {
    10021179    if (obj == null) return true;
    1003     if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
    1004     for (var key in obj) if (_.has(obj, key)) return false;
    1005     return true;
     1180    if (isArrayLike(obj) && (_.isArray(obj) || _.isString(obj) || _.isArguments(obj))) return obj.length === 0;
     1181    return _.keys(obj).length === 0;
    10061182  };
    10071183
    10081184  // Is a given value a DOM element?
     
    10131189  // Is a given value an array?
    10141190  // Delegates to ECMA5's native Array.isArray
    10151191  _.isArray = nativeIsArray || function(obj) {
    1016     return toString.call(obj) == '[object Array]';
     1192    return toString.call(obj) === '[object Array]';
    10171193  };
    10181194
    10191195  // Is a given variable an object?
    10201196  _.isObject = function(obj) {
    1021     return obj === Object(obj);
     1197    var type = typeof obj;
     1198    return type === 'function' || type === 'object' && !!obj;
    10221199  };
    10231200
    1024   // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
    1025   each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
     1201  // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError.
     1202  _.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'], function(name) {
    10261203    _['is' + name] = function(obj) {
    1027       return toString.call(obj) == '[object ' + name + ']';
     1204      return toString.call(obj) === '[object ' + name + ']';
    10281205    };
    10291206  });
    10301207
    1031   // Define a fallback version of the method in browsers (ahem, IE), where
     1208  // Define a fallback version of the method in browsers (ahem, IE < 9), where
    10321209  // there isn't any inspectable "Arguments" type.
    10331210  if (!_.isArguments(arguments)) {
    10341211    _.isArguments = function(obj) {
    1035       return !!(obj && _.has(obj, 'callee'));
     1212      return _.has(obj, 'callee');
    10361213    };
    10371214  }
    10381215
    1039   // Optimize `isFunction` if appropriate.
    1040   if (typeof (/./) !== 'function') {
     1216  // Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8,
     1217  // IE 11 (#1621), and in Safari 8 (#1929).
     1218  if (typeof /./ != 'function' && typeof Int8Array != 'object') {
    10411219    _.isFunction = function(obj) {
    1042       return typeof obj === 'function';
     1220      return typeof obj == 'function' || false;
    10431221    };
    10441222  }
    10451223
     
    10501228
    10511229  // Is the given value `NaN`? (NaN is the only number which does not equal itself).
    10521230  _.isNaN = function(obj) {
    1053     return _.isNumber(obj) && obj != +obj;
     1231    return _.isNumber(obj) && obj !== +obj;
    10541232  };
    10551233
    10561234  // Is a given value a boolean?
    10571235  _.isBoolean = function(obj) {
    1058     return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
     1236    return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
    10591237  };
    10601238
    10611239  // Is a given value equal to null?
     
    10711249  // Shortcut function for checking if an object has a given property directly
    10721250  // on itself (in other words, not on a prototype).
    10731251  _.has = function(obj, key) {
    1074     return hasOwnProperty.call(obj, key);
     1252    return obj != null && hasOwnProperty.call(obj, key);
    10751253  };
    10761254
    10771255  // Utility Functions
     
    10841262    return this;
    10851263  };
    10861264
    1087   // Keep the identity function around for default iterators.
     1265  // Keep the identity function around for default iteratees.
    10881266  _.identity = function(value) {
    10891267    return value;
    10901268  };
    10911269
     1270  // Predicate-generating functions. Often useful outside of Underscore.
    10921271  _.constant = function(value) {
    1093     return function () {
     1272    return function() {
    10941273      return value;
    10951274    };
    10961275  };
    10971276
     1277  _.noop = function(){};
     1278
    10981279  _.property = function(key) {
    10991280    return function(obj) {
     1281      return obj == null ? void 0 : obj[key];
     1282    };
     1283  };
     1284
     1285  // Generates a function for a given object that returns a given property.
     1286  _.propertyOf = function(obj) {
     1287    return obj == null ? function(){} : function(key) {
    11001288      return obj[key];
    11011289    };
    11021290  };
    11031291
    1104   // Returns a predicate for checking whether an object has a given set of `key:value` pairs.
    1105   _.matches = function(attrs) {
     1292  // Returns a predicate for checking whether an object has a given set of
     1293  // `key:value` pairs.
     1294  _.matcher = _.matches = function(attrs) {
     1295    attrs = _.extendOwn({}, attrs);
    11061296    return function(obj) {
    1107       if (obj === attrs) return true; //avoid comparing an object to itself.
    1108       for (var key in attrs) {
    1109         if (attrs[key] !== obj[key])
    1110           return false;
    1111       }
    1112       return true;
    1113     }
     1297      return _.isMatch(obj, attrs);
     1298    };
    11141299  };
    11151300
    11161301  // Run a function **n** times.
    1117   _.times = function(n, iterator, context) {
     1302  _.times = function(n, iteratee, context) {
    11181303    var accum = Array(Math.max(0, n));
    1119     for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
     1304    iteratee = optimizeCb(iteratee, context, 1);
     1305    for (var i = 0; i < n; i++) accum[i] = iteratee(i);
    11201306    return accum;
    11211307  };
    11221308
     
    11301316  };
    11311317
    11321318  // A (possibly faster) way to get the current timestamp as an integer.
    1133   _.now = Date.now || function() { return new Date().getTime(); };
    1134 
    1135   // List of HTML entities for escaping.
    1136   var entityMap = {
    1137     escape: {
    1138       '&': '&amp;',
    1139       '<': '&lt;',
    1140       '>': '&gt;',
    1141       '"': '&quot;',
    1142       "'": '&#x27;'
    1143     }
     1319  _.now = Date.now || function() {
     1320    return new Date().getTime();
    11441321  };
    1145   entityMap.unescape = _.invert(entityMap.escape);
    11461322
    1147   // Regexes containing the keys and values listed immediately above.
    1148   var entityRegexes = {
    1149     escape:   new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'),
    1150     unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g')
     1323   // List of HTML entities for escaping.
     1324  var escapeMap = {
     1325    '&': '&amp;',
     1326    '<': '&lt;',
     1327    '>': '&gt;',
     1328    '"': '&quot;',
     1329    "'": '&#x27;',
     1330    '`': '&#x60;'
    11511331  };
     1332  var unescapeMap = _.invert(escapeMap);
    11521333
    11531334  // Functions for escaping and unescaping strings to/from HTML interpolation.
    1154   _.each(['escape', 'unescape'], function(method) {
    1155     _[method] = function(string) {
    1156       if (string == null) return '';
    1157       return ('' + string).replace(entityRegexes[method], function(match) {
    1158         return entityMap[method][match];
    1159       });
     1335  var createEscaper = function(map) {
     1336    var escaper = function(match) {
     1337      return map[match];
    11601338    };
    1161   });
     1339    // Regexes for identifying a key that needs to be escaped
     1340    var source = '(?:' + _.keys(map).join('|') + ')';
     1341    var testRegexp = RegExp(source);
     1342    var replaceRegexp = RegExp(source, 'g');
     1343    return function(string) {
     1344      string = string == null ? '' : '' + string;
     1345      return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
     1346    };
     1347  };
     1348  _.escape = createEscaper(escapeMap);
     1349  _.unescape = createEscaper(unescapeMap);
    11621350
    11631351  // If the value of the named `property` is a function then invoke it with the
    11641352  // `object` as context; otherwise, return it.
    1165   _.result = function(object, property) {
    1166     if (object == null) return void 0;
    1167     var value = object[property];
     1353  _.result = function(object, property, fallback) {
     1354    var value = object == null ? void 0 : object[property];
     1355    if (value === void 0) {
     1356      value = fallback;
     1357    }
    11681358    return _.isFunction(value) ? value.call(object) : value;
    11691359  };
    11701360
    1171   // Add your own custom functions to the Underscore object.
    1172   _.mixin = function(obj) {
    1173     each(_.functions(obj), function(name) {
    1174       var func = _[name] = obj[name];
    1175       _.prototype[name] = function() {
    1176         var args = [this._wrapped];
    1177         push.apply(args, arguments);
    1178         return result.call(this, func.apply(_, args));
    1179       };
    1180     });
    1181   };
    1182 
    11831361  // Generate a unique integer id (unique within the entire client session).
    11841362  // Useful for temporary DOM ids.
    11851363  var idCounter = 0;
     
    12081386    '\\':     '\\',
    12091387    '\r':     'r',
    12101388    '\n':     'n',
    1211     '\t':     't',
    12121389    '\u2028': 'u2028',
    12131390    '\u2029': 'u2029'
    12141391  };
    12151392
    1216   var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
     1393  var escaper = /\\|'|\r|\n|\u2028|\u2029/g;
    12171394
     1395  var escapeChar = function(match) {
     1396    return '\\' + escapes[match];
     1397  };
     1398
    12181399  // JavaScript micro-templating, similar to John Resig's implementation.
    12191400  // Underscore templating handles arbitrary delimiters, preserves whitespace,
    12201401  // and correctly escapes quotes within interpolated code.
    1221   _.template = function(text, data, settings) {
    1222     var render;
     1402  // NB: `oldSettings` only exists for backwards compatibility.
     1403  _.template = function(text, settings, oldSettings) {
     1404    if (!settings && oldSettings) settings = oldSettings;
    12231405    settings = _.defaults({}, settings, _.templateSettings);
    12241406
    12251407    // Combine delimiters into one regular expression via alternation.
    1226     var matcher = new RegExp([
     1408    var matcher = RegExp([
    12271409      (settings.escape || noMatch).source,
    12281410      (settings.interpolate || noMatch).source,
    12291411      (settings.evaluate || noMatch).source
     
    12331415    var index = 0;
    12341416    var source = "__p+='";
    12351417    text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
    1236       source += text.slice(index, offset)
    1237         .replace(escaper, function(match) { return '\\' + escapes[match]; });
     1418      source += text.slice(index, offset).replace(escaper, escapeChar);
     1419      index = offset + match.length;
    12381420
    12391421      if (escape) {
    12401422        source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
    1241       }
    1242       if (interpolate) {
     1423      } else if (interpolate) {
    12431424        source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
    1244       }
    1245       if (evaluate) {
     1425      } else if (evaluate) {
    12461426        source += "';\n" + evaluate + "\n__p+='";
    12471427      }
    1248       index = offset + match.length;
     1428
     1429      // Adobe VMs need the match returned to produce the correct offest.
    12491430      return match;
    12501431    });
    12511432    source += "';\n";
     
    12551436
    12561437    source = "var __t,__p='',__j=Array.prototype.join," +
    12571438      "print=function(){__p+=__j.call(arguments,'');};\n" +
    1258       source + "return __p;\n";
     1439      source + 'return __p;\n';
    12591440
    12601441    try {
    1261       render = new Function(settings.variable || 'obj', '_', source);
     1442      var render = new Function(settings.variable || 'obj', '_', source);
    12621443    } catch (e) {
    12631444      e.source = source;
    12641445      throw e;
    12651446    }
    12661447
    1267     if (data) return render(data, _);
    12681448    var template = function(data) {
    12691449      return render.call(this, data, _);
    12701450    };
    12711451
    1272     // Provide the compiled function source as a convenience for precompilation.
    1273     template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';
     1452    // Provide the compiled source as a convenience for precompilation.
     1453    var argument = settings.variable || 'obj';
     1454    template.source = 'function(' + argument + '){\n' + source + '}';
    12741455
    12751456    return template;
    12761457  };
    12771458
    1278   // Add a "chain" function, which will delegate to the wrapper.
     1459  // Add a "chain" function. Start chaining a wrapped Underscore object.
    12791460  _.chain = function(obj) {
    1280     return _(obj).chain();
     1461    var instance = _(obj);
     1462    instance._chain = true;
     1463    return instance;
    12811464  };
    12821465
    12831466  // OOP
     
    12871470  // underscore functions. Wrapped objects may be chained.
    12881471
    12891472  // Helper function to continue chaining intermediate results.
    1290   var result = function(obj) {
    1291     return this._chain ? _(obj).chain() : obj;
     1473  var result = function(instance, obj) {
     1474    return instance._chain ? _(obj).chain() : obj;
    12921475  };
    12931476
     1477  // Add your own custom functions to the Underscore object.
     1478  _.mixin = function(obj) {
     1479    _.each(_.functions(obj), function(name) {
     1480      var func = _[name] = obj[name];
     1481      _.prototype[name] = function() {
     1482        var args = [this._wrapped];
     1483        push.apply(args, arguments);
     1484        return result(this, func.apply(_, args));
     1485      };
     1486    });
     1487  };
     1488
    12941489  // Add all of the Underscore functions to the wrapper object.
    12951490  _.mixin(_);
    12961491
    12971492  // Add all mutator Array functions to the wrapper.
    1298   each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
     1493  _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
    12991494    var method = ArrayProto[name];
    13001495    _.prototype[name] = function() {
    13011496      var obj = this._wrapped;
    13021497      method.apply(obj, arguments);
    1303       if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0];
    1304       return result.call(this, obj);
     1498      if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
     1499      return result(this, obj);
    13051500    };
    13061501  });
    13071502
    13081503  // Add all accessor Array functions to the wrapper.
    1309   each(['concat', 'join', 'slice'], function(name) {
     1504  _.each(['concat', 'join', 'slice'], function(name) {
    13101505    var method = ArrayProto[name];
    13111506    _.prototype[name] = function() {
    1312       return result.call(this, method.apply(this._wrapped, arguments));
     1507      return result(this, method.apply(this._wrapped, arguments));
    13131508    };
    13141509  });
    13151510
    1316   _.extend(_.prototype, {
     1511  // Extracts the result from a wrapped and chained object.
     1512  _.prototype.value = function() {
     1513    return this._wrapped;
     1514  };
    13171515
    1318     // Start chaining a wrapped Underscore object.
    1319     chain: function() {
    1320       this._chain = true;
    1321       return this;
    1322     },
     1516  // Provide unwrapping proxy for some methods used in engine operations
     1517  // such as arithmetic and JSON stringification.
     1518  _.prototype.valueOf = _.prototype.toJSON = _.prototype.value;
    13231519
    1324     // Extracts the result from a wrapped and chained object.
    1325     value: function() {
    1326       return this._wrapped;
    1327     }
     1520  _.prototype.toString = function() {
     1521    return '' + this._wrapped;
     1522  };
    13281523
    1329   });
    1330 
    13311524  // AMD registration happens at the end for compatibility with AMD loaders
    13321525  // that may not enforce next-turn semantics on modules. Even though general
    13331526  // practice for AMD registration is to be anonymous, underscore registers
     
    13401533      return _;
    13411534    });
    13421535  }
    1343 }).call(this);
     1536}.call(this));
  • src/wp-includes/js/underscore.min.js

     
    1 //     Underscore.js 1.6.0
     1//     Underscore.js 1.8.2
    22//     http://underscorejs.org
    3 //     (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
     3//     (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
    44//     Underscore may be freely distributed under the MIT license.
    5 (function(){var n=this,t=n._,r={},e=Array.prototype,u=Object.prototype,i=Function.prototype,a=e.push,o=e.slice,c=e.concat,l=u.toString,f=u.hasOwnProperty,s=e.forEach,p=e.map,h=e.reduce,v=e.reduceRight,g=e.filter,d=e.every,m=e.some,y=e.indexOf,b=e.lastIndexOf,x=Array.isArray,w=Object.keys,_=i.bind,j=function(n){return n instanceof j?n:this instanceof j?void(this._wrapped=n):new j(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=j),exports._=j):n._=j,j.VERSION="1.6.0";var A=j.each=j.forEach=function(n,t,e){if(null==n)return n;if(s&&n.forEach===s)n.forEach(t,e);else if(n.length===+n.length){for(var u=0,i=n.length;i>u;u++)if(t.call(e,n[u],u,n)===r)return}else for(var a=j.keys(n),u=0,i=a.length;i>u;u++)if(t.call(e,n[a[u]],a[u],n)===r)return;return n};j.map=j.collect=function(n,t,r){var e=[];return null==n?e:p&&n.map===p?n.map(t,r):(A(n,function(n,u,i){e.push(t.call(r,n,u,i))}),e)};var O="Reduce of empty array with no initial value";j.reduce=j.foldl=j.inject=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),h&&n.reduce===h)return e&&(t=j.bind(t,e)),u?n.reduce(t,r):n.reduce(t);if(A(n,function(n,i,a){u?r=t.call(e,r,n,i,a):(r=n,u=!0)}),!u)throw new TypeError(O);return r},j.reduceRight=j.foldr=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),v&&n.reduceRight===v)return e&&(t=j.bind(t,e)),u?n.reduceRight(t,r):n.reduceRight(t);var i=n.length;if(i!==+i){var a=j.keys(n);i=a.length}if(A(n,function(o,c,l){c=a?a[--i]:--i,u?r=t.call(e,r,n[c],c,l):(r=n[c],u=!0)}),!u)throw new TypeError(O);return r},j.find=j.detect=function(n,t,r){var e;return k(n,function(n,u,i){return t.call(r,n,u,i)?(e=n,!0):void 0}),e},j.filter=j.select=function(n,t,r){var e=[];return null==n?e:g&&n.filter===g?n.filter(t,r):(A(n,function(n,u,i){t.call(r,n,u,i)&&e.push(n)}),e)},j.reject=function(n,t,r){return j.filter(n,function(n,e,u){return!t.call(r,n,e,u)},r)},j.every=j.all=function(n,t,e){t||(t=j.identity);var u=!0;return null==n?u:d&&n.every===d?n.every(t,e):(A(n,function(n,i,a){return(u=u&&t.call(e,n,i,a))?void 0:r}),!!u)};var k=j.some=j.any=function(n,t,e){t||(t=j.identity);var u=!1;return null==n?u:m&&n.some===m?n.some(t,e):(A(n,function(n,i,a){return u||(u=t.call(e,n,i,a))?r:void 0}),!!u)};j.contains=j.include=function(n,t){return null==n?!1:y&&n.indexOf===y?n.indexOf(t)!=-1:k(n,function(n){return n===t})},j.invoke=function(n,t){var r=o.call(arguments,2),e=j.isFunction(t);return j.map(n,function(n){return(e?t:n[t]).apply(n,r)})},j.pluck=function(n,t){return j.map(n,j.property(t))},j.where=function(n,t){return j.filter(n,j.matches(t))},j.findWhere=function(n,t){return j.find(n,j.matches(t))},j.max=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)return Math.max.apply(Math,n);var e=-1/0,u=-1/0;return A(n,function(n,i,a){var o=t?t.call(r,n,i,a):n;o>u&&(e=n,u=o)}),e},j.min=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)return Math.min.apply(Math,n);var e=1/0,u=1/0;return A(n,function(n,i,a){var o=t?t.call(r,n,i,a):n;u>o&&(e=n,u=o)}),e},j.shuffle=function(n){var t,r=0,e=[];return A(n,function(n){t=j.random(r++),e[r-1]=e[t],e[t]=n}),e},j.sample=function(n,t,r){return null==t||r?(n.length!==+n.length&&(n=j.values(n)),n[j.random(n.length-1)]):j.shuffle(n).slice(0,Math.max(0,t))};var E=function(n){return null==n?j.identity:j.isFunction(n)?n:j.property(n)};j.sortBy=function(n,t,r){return t=E(t),j.pluck(j.map(n,function(n,e,u){return{value:n,index:e,criteria:t.call(r,n,e,u)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index-t.index}),"value")};var F=function(n){return function(t,r,e){var u={};return r=E(r),A(t,function(i,a){var o=r.call(e,i,a,t);n(u,o,i)}),u}};j.groupBy=F(function(n,t,r){j.has(n,t)?n[t].push(r):n[t]=[r]}),j.indexBy=F(function(n,t,r){n[t]=r}),j.countBy=F(function(n,t){j.has(n,t)?n[t]++:n[t]=1}),j.sortedIndex=function(n,t,r,e){r=E(r);for(var u=r.call(e,t),i=0,a=n.length;a>i;){var o=i+a>>>1;r.call(e,n[o])<u?i=o+1:a=o}return i},j.toArray=function(n){return n?j.isArray(n)?o.call(n):n.length===+n.length?j.map(n,j.identity):j.values(n):[]},j.size=function(n){return null==n?0:n.length===+n.length?n.length:j.keys(n).length},j.first=j.head=j.take=function(n,t,r){return null==n?void 0:null==t||r?n[0]:0>t?[]:o.call(n,0,t)},j.initial=function(n,t,r){return o.call(n,0,n.length-(null==t||r?1:t))},j.last=function(n,t,r){return null==n?void 0:null==t||r?n[n.length-1]:o.call(n,Math.max(n.length-t,0))},j.rest=j.tail=j.drop=function(n,t,r){return o.call(n,null==t||r?1:t)},j.compact=function(n){return j.filter(n,j.identity)};var M=function(n,t,r){return t&&j.every(n,j.isArray)?c.apply(r,n):(A(n,function(n){j.isArray(n)||j.isArguments(n)?t?a.apply(r,n):M(n,t,r):r.push(n)}),r)};j.flatten=function(n,t){return M(n,t,[])},j.without=function(n){return j.difference(n,o.call(arguments,1))},j.partition=function(n,t){var r=[],e=[];return A(n,function(n){(t(n)?r:e).push(n)}),[r,e]},j.uniq=j.unique=function(n,t,r,e){j.isFunction(t)&&(e=r,r=t,t=!1);var u=r?j.map(n,r,e):n,i=[],a=[];return A(u,function(r,e){(t?e&&a[a.length-1]===r:j.contains(a,r))||(a.push(r),i.push(n[e]))}),i},j.union=function(){return j.uniq(j.flatten(arguments,!0))},j.intersection=function(n){var t=o.call(arguments,1);return j.filter(j.uniq(n),function(n){return j.every(t,function(t){return j.contains(t,n)})})},j.difference=function(n){var t=c.apply(e,o.call(arguments,1));return j.filter(n,function(n){return!j.contains(t,n)})},j.zip=function(){for(var n=j.max(j.pluck(arguments,"length").concat(0)),t=new Array(n),r=0;n>r;r++)t[r]=j.pluck(arguments,""+r);return t},j.object=function(n,t){if(null==n)return{};for(var r={},e=0,u=n.length;u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},j.indexOf=function(n,t,r){if(null==n)return-1;var e=0,u=n.length;if(r){if("number"!=typeof r)return e=j.sortedIndex(n,t),n[e]===t?e:-1;e=0>r?Math.max(0,u+r):r}if(y&&n.indexOf===y)return n.indexOf(t,r);for(;u>e;e++)if(n[e]===t)return e;return-1},j.lastIndexOf=function(n,t,r){if(null==n)return-1;var e=null!=r;if(b&&n.lastIndexOf===b)return e?n.lastIndexOf(t,r):n.lastIndexOf(t);for(var u=e?r:n.length;u--;)if(n[u]===t)return u;return-1},j.range=function(n,t,r){arguments.length<=1&&(t=n||0,n=0),r=arguments[2]||1;for(var e=Math.max(Math.ceil((t-n)/r),0),u=0,i=new Array(e);e>u;)i[u++]=n,n+=r;return i};var R=function(){};j.bind=function(n,t){var r,e;if(_&&n.bind===_)return _.apply(n,o.call(arguments,1));if(!j.isFunction(n))throw new TypeError;return r=o.call(arguments,2),e=function(){if(!(this instanceof e))return n.apply(t,r.concat(o.call(arguments)));R.prototype=n.prototype;var u=new R;R.prototype=null;var i=n.apply(u,r.concat(o.call(arguments)));return Object(i)===i?i:u}},j.partial=function(n){var t=o.call(arguments,1);return function(){for(var r=0,e=t.slice(),u=0,i=e.length;i>u;u++)e[u]===j&&(e[u]=arguments[r++]);for(;r<arguments.length;)e.push(arguments[r++]);return n.apply(this,e)}},j.bindAll=function(n){var t=o.call(arguments,1);if(0===t.length)throw new Error("bindAll must be passed function names");return A(t,function(t){n[t]=j.bind(n[t],n)}),n},j.memoize=function(n,t){var r={};return t||(t=j.identity),function(){var e=t.apply(this,arguments);return j.has(r,e)?r[e]:r[e]=n.apply(this,arguments)}},j.delay=function(n,t){var r=o.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},j.defer=function(n){return j.delay.apply(j,[n,1].concat(o.call(arguments,1)))},j.throttle=function(n,t,r){var e,u,i,a=null,o=0;r||(r={});var c=function(){o=r.leading===!1?0:j.now(),a=null,i=n.apply(e,u),e=u=null};return function(){var l=j.now();o||r.leading!==!1||(o=l);var f=t-(l-o);return e=this,u=arguments,0>=f?(clearTimeout(a),a=null,o=l,i=n.apply(e,u),e=u=null):a||r.trailing===!1||(a=setTimeout(c,f)),i}},j.debounce=function(n,t,r){var e,u,i,a,o,c=function(){var l=j.now()-a;t>l?e=setTimeout(c,t-l):(e=null,r||(o=n.apply(i,u),i=u=null))};return function(){i=this,u=arguments,a=j.now();var l=r&&!e;return e||(e=setTimeout(c,t)),l&&(o=n.apply(i,u),i=u=null),o}},j.once=function(n){var t,r=!1;return function(){return r?t:(r=!0,t=n.apply(this,arguments),n=null,t)}},j.wrap=function(n,t){return j.partial(t,n)},j.compose=function(){var n=arguments;return function(){for(var t=arguments,r=n.length-1;r>=0;r--)t=[n[r].apply(this,t)];return t[0]}},j.after=function(n,t){return function(){return--n<1?t.apply(this,arguments):void 0}},j.keys=function(n){if(!j.isObject(n))return[];if(w)return w(n);var t=[];for(var r in n)j.has(n,r)&&t.push(r);return t},j.values=function(n){for(var t=j.keys(n),r=t.length,e=new Array(r),u=0;r>u;u++)e[u]=n[t[u]];return e},j.pairs=function(n){for(var t=j.keys(n),r=t.length,e=new Array(r),u=0;r>u;u++)e[u]=[t[u],n[t[u]]];return e},j.invert=function(n){for(var t={},r=j.keys(n),e=0,u=r.length;u>e;e++)t[n[r[e]]]=r[e];return t},j.functions=j.methods=function(n){var t=[];for(var r in n)j.isFunction(n[r])&&t.push(r);return t.sort()},j.extend=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]=t[r]}),n},j.pick=function(n){var t={},r=c.apply(e,o.call(arguments,1));return A(r,function(r){r in n&&(t[r]=n[r])}),t},j.omit=function(n){var t={},r=c.apply(e,o.call(arguments,1));for(var u in n)j.contains(r,u)||(t[u]=n[u]);return t},j.defaults=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]===void 0&&(n[r]=t[r])}),n},j.clone=function(n){return j.isObject(n)?j.isArray(n)?n.slice():j.extend({},n):n},j.tap=function(n,t){return t(n),n};var S=function(n,t,r,e){if(n===t)return 0!==n||1/n==1/t;if(null==n||null==t)return n===t;n instanceof j&&(n=n._wrapped),t instanceof j&&(t=t._wrapped);var u=l.call(n);if(u!=l.call(t))return!1;switch(u){case"[object String]":return n==String(t);case"[object Number]":return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case"[object Date]":case"[object Boolean]":return+n==+t;case"[object RegExp]":return n.source==t.source&&n.global==t.global&&n.multiline==t.multiline&&n.ignoreCase==t.ignoreCase}if("object"!=typeof n||"object"!=typeof t)return!1;for(var i=r.length;i--;)if(r[i]==n)return e[i]==t;var a=n.constructor,o=t.constructor;if(a!==o&&!(j.isFunction(a)&&a instanceof a&&j.isFunction(o)&&o instanceof o)&&"constructor"in n&&"constructor"in t)return!1;r.push(n),e.push(t);var c=0,f=!0;if("[object Array]"==u){if(c=n.length,f=c==t.length)for(;c--&&(f=S(n[c],t[c],r,e)););}else{for(var s in n)if(j.has(n,s)&&(c++,!(f=j.has(t,s)&&S(n[s],t[s],r,e))))break;if(f){for(s in t)if(j.has(t,s)&&!c--)break;f=!c}}return r.pop(),e.pop(),f};j.isEqual=function(n,t){return S(n,t,[],[])},j.isEmpty=function(n){if(null==n)return!0;if(j.isArray(n)||j.isString(n))return 0===n.length;for(var t in n)if(j.has(n,t))return!1;return!0},j.isElement=function(n){return!(!n||1!==n.nodeType)},j.isArray=x||function(n){return"[object Array]"==l.call(n)},j.isObject=function(n){return n===Object(n)},A(["Arguments","Function","String","Number","Date","RegExp"],function(n){j["is"+n]=function(t){return l.call(t)=="[object "+n+"]"}}),j.isArguments(arguments)||(j.isArguments=function(n){return!(!n||!j.has(n,"callee"))}),"function"!=typeof/./&&(j.isFunction=function(n){return"function"==typeof n}),j.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},j.isNaN=function(n){return j.isNumber(n)&&n!=+n},j.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"==l.call(n)},j.isNull=function(n){return null===n},j.isUndefined=function(n){return n===void 0},j.has=function(n,t){return f.call(n,t)},j.noConflict=function(){return n._=t,this},j.identity=function(n){return n},j.constant=function(n){return function(){return n}},j.property=function(n){return function(t){return t[n]}},j.matches=function(n){return function(t){if(t===n)return!0;for(var r in n)if(n[r]!==t[r])return!1;return!0}},j.times=function(n,t,r){for(var e=Array(Math.max(0,n)),u=0;n>u;u++)e[u]=t.call(r,u);return e},j.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))},j.now=Date.now||function(){return(new Date).getTime()};var T={escape:{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"}};T.unescape=j.invert(T.escape);var I={escape:new RegExp("["+j.keys(T.escape).join("")+"]","g"),unescape:new RegExp("("+j.keys(T.unescape).join("|")+")","g")};j.each(["escape","unescape"],function(n){j[n]=function(t){return null==t?"":(""+t).replace(I[n],function(t){return T[n][t]})}}),j.result=function(n,t){if(null==n)return void 0;var r=n[t];return j.isFunction(r)?r.call(n):r},j.mixin=function(n){A(j.functions(n),function(t){var r=j[t]=n[t];j.prototype[t]=function(){var n=[this._wrapped];return a.apply(n,arguments),z.call(this,r.apply(j,n))}})};var N=0;j.uniqueId=function(n){var t=++N+"";return n?n+t:t},j.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var q=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n","   ":"t","\u2028":"u2028","\u2029":"u2029"},D=/\\|'|\r|\n|\t|\u2028|\u2029/g;j.template=function(n,t,r){var e;r=j.defaults({},r,j.templateSettings);var u=new RegExp([(r.escape||q).source,(r.interpolate||q).source,(r.evaluate||q).source].join("|")+"|$","g"),i=0,a="__p+='";n.replace(u,function(t,r,e,u,o){return a+=n.slice(i,o).replace(D,function(n){return"\\"+B[n]}),r&&(a+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'"),e&&(a+="'+\n((__t=("+e+"))==null?'':__t)+\n'"),u&&(a+="';\n"+u+"\n__p+='"),i=o+t.length,t}),a+="';\n",r.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{e=new Function(r.variable||"obj","_",a)}catch(o){throw o.source=a,o}if(t)return e(t,j);var c=function(n){return e.call(this,n,j)};return c.source="function("+(r.variable||"obj")+"){\n"+a+"}",c},j.chain=function(n){return j(n).chain()};var z=function(n){return this._chain?j(n).chain():n};j.mixin(j),A(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=e[n];j.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!=n&&"splice"!=n||0!==r.length||delete r[0],z.call(this,r)}}),A(["concat","join","slice"],function(n){var t=e[n];j.prototype[n]=function(){return z.call(this,t.apply(this._wrapped,arguments))}}),j.extend(j.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}}),"function"==typeof define&&define.amd&&define("underscore",[],function(){return j})}).call(this);
    6 //# sourceMappingURL=underscore-min.map
    7  No newline at end of file
     5(function(){function n(n){function t(t,r,e,u,i,o){for(;i>=0&&o>i;i+=n){var a=u?u[i]:i;e=r(e,t[a],a,t)}return e}return function(r,e,u,i){e=d(e,i,4);var o=!w(r)&&m.keys(r),a=(o||r).length,c=n>0?0:a-1;return arguments.length<3&&(u=r[o?o[c]:c],c+=n),t(r,e,u,o,c,a)}}function t(n){return function(t,r,e){r=b(r,e);for(var u=null!=t&&t.length,i=n>0?0:u-1;i>=0&&u>i;i+=n)if(r(t[i],i,t))return i;return-1}}function r(n,t){var r=S.length,e=n.constructor,u=m.isFunction(e)&&e.prototype||o,i="constructor";for(m.has(n,i)&&!m.contains(t,i)&&t.push(i);r--;)i=S[r],i in n&&n[i]!==u[i]&&!m.contains(t,i)&&t.push(i)}var e=this,u=e._,i=Array.prototype,o=Object.prototype,a=Function.prototype,c=i.push,l=i.slice,f=o.toString,s=o.hasOwnProperty,p=Array.isArray,h=Object.keys,v=a.bind,g=Object.create,y=function(){},m=function(n){return n instanceof m?n:this instanceof m?void(this._wrapped=n):new m(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=m),exports._=m):e._=m,m.VERSION="1.8.2";var d=function(n,t,r){if(t===void 0)return n;switch(null==r?3:r){case 1:return function(r){return n.call(t,r)};case 2:return function(r,e){return n.call(t,r,e)};case 3:return function(r,e,u){return n.call(t,r,e,u)};case 4:return function(r,e,u,i){return n.call(t,r,e,u,i)}}return function(){return n.apply(t,arguments)}},b=function(n,t,r){return null==n?m.identity:m.isFunction(n)?d(n,t,r):m.isObject(n)?m.matcher(n):m.property(n)};m.iteratee=function(n,t){return b(n,t,1/0)};var x=function(n,t){return function(r){var e=arguments.length;if(2>e||null==r)return r;for(var u=1;e>u;u++)for(var i=arguments[u],o=n(i),a=o.length,c=0;a>c;c++){var l=o[c];t&&r[l]!==void 0||(r[l]=i[l])}return r}},_=function(n){if(!m.isObject(n))return{};if(g)return g(n);y.prototype=n;var t=new y;return y.prototype=null,t},j=Math.pow(2,53)-1,w=function(n){var t=n&&n.length;return"number"==typeof t&&t>=0&&j>=t};m.each=m.forEach=function(n,t,r){t=d(t,r);var e,u;if(w(n))for(e=0,u=n.length;u>e;e++)t(n[e],e,n);else{var i=m.keys(n);for(e=0,u=i.length;u>e;e++)t(n[i[e]],i[e],n)}return n},m.map=m.collect=function(n,t,r){t=b(t,r);for(var e=!w(n)&&m.keys(n),u=(e||n).length,i=Array(u),o=0;u>o;o++){var a=e?e[o]:o;i[o]=t(n[a],a,n)}return i},m.reduce=m.foldl=m.inject=n(1),m.reduceRight=m.foldr=n(-1),m.find=m.detect=function(n,t,r){var e;return e=w(n)?m.findIndex(n,t,r):m.findKey(n,t,r),e!==void 0&&e!==-1?n[e]:void 0},m.filter=m.select=function(n,t,r){var e=[];return t=b(t,r),m.each(n,function(n,r,u){t(n,r,u)&&e.push(n)}),e},m.reject=function(n,t,r){return m.filter(n,m.negate(b(t)),r)},m.every=m.all=function(n,t,r){t=b(t,r);for(var e=!w(n)&&m.keys(n),u=(e||n).length,i=0;u>i;i++){var o=e?e[i]:i;if(!t(n[o],o,n))return!1}return!0},m.some=m.any=function(n,t,r){t=b(t,r);for(var e=!w(n)&&m.keys(n),u=(e||n).length,i=0;u>i;i++){var o=e?e[i]:i;if(t(n[o],o,n))return!0}return!1},m.contains=m.includes=m.include=function(n,t,r){return w(n)||(n=m.values(n)),m.indexOf(n,t,"number"==typeof r&&r)>=0},m.invoke=function(n,t){var r=l.call(arguments,2),e=m.isFunction(t);return m.map(n,function(n){var u=e?t:n[t];return null==u?u:u.apply(n,r)})},m.pluck=function(n,t){return m.map(n,m.property(t))},m.where=function(n,t){return m.filter(n,m.matcher(t))},m.findWhere=function(n,t){return m.find(n,m.matcher(t))},m.max=function(n,t,r){var e,u,i=-1/0,o=-1/0;if(null==t&&null!=n){n=w(n)?n:m.values(n);for(var a=0,c=n.length;c>a;a++)e=n[a],e>i&&(i=e)}else t=b(t,r),m.each(n,function(n,r,e){u=t(n,r,e),(u>o||u===-1/0&&i===-1/0)&&(i=n,o=u)});return i},m.min=function(n,t,r){var e,u,i=1/0,o=1/0;if(null==t&&null!=n){n=w(n)?n:m.values(n);for(var a=0,c=n.length;c>a;a++)e=n[a],i>e&&(i=e)}else t=b(t,r),m.each(n,function(n,r,e){u=t(n,r,e),(o>u||1/0===u&&1/0===i)&&(i=n,o=u)});return i},m.shuffle=function(n){for(var t,r=w(n)?n:m.values(n),e=r.length,u=Array(e),i=0;e>i;i++)t=m.random(0,i),t!==i&&(u[i]=u[t]),u[t]=r[i];return u},m.sample=function(n,t,r){return null==t||r?(w(n)||(n=m.values(n)),n[m.random(n.length-1)]):m.shuffle(n).slice(0,Math.max(0,t))},m.sortBy=function(n,t,r){return t=b(t,r),m.pluck(m.map(n,function(n,r,e){return{value:n,index:r,criteria:t(n,r,e)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index-t.index}),"value")};var A=function(n){return function(t,r,e){var u={};return r=b(r,e),m.each(t,function(e,i){var o=r(e,i,t);n(u,e,o)}),u}};m.groupBy=A(function(n,t,r){m.has(n,r)?n[r].push(t):n[r]=[t]}),m.indexBy=A(function(n,t,r){n[r]=t}),m.countBy=A(function(n,t,r){m.has(n,r)?n[r]++:n[r]=1}),m.toArray=function(n){return n?m.isArray(n)?l.call(n):w(n)?m.map(n,m.identity):m.values(n):[]},m.size=function(n){return null==n?0:w(n)?n.length:m.keys(n).length},m.partition=function(n,t,r){t=b(t,r);var e=[],u=[];return m.each(n,function(n,r,i){(t(n,r,i)?e:u).push(n)}),[e,u]},m.first=m.head=m.take=function(n,t,r){return null==n?void 0:null==t||r?n[0]:m.initial(n,n.length-t)},m.initial=function(n,t,r){return l.call(n,0,Math.max(0,n.length-(null==t||r?1:t)))},m.last=function(n,t,r){return null==n?void 0:null==t||r?n[n.length-1]:m.rest(n,Math.max(0,n.length-t))},m.rest=m.tail=m.drop=function(n,t,r){return l.call(n,null==t||r?1:t)},m.compact=function(n){return m.filter(n,m.identity)};var k=function(n,t,r,e){for(var u=[],i=0,o=e||0,a=n&&n.length;a>o;o++){var c=n[o];if(w(c)&&(m.isArray(c)||m.isArguments(c))){t||(c=k(c,t,r));var l=0,f=c.length;for(u.length+=f;f>l;)u[i++]=c[l++]}else r||(u[i++]=c)}return u};m.flatten=function(n,t){return k(n,t,!1)},m.without=function(n){return m.difference(n,l.call(arguments,1))},m.uniq=m.unique=function(n,t,r,e){if(null==n)return[];m.isBoolean(t)||(e=r,r=t,t=!1),null!=r&&(r=b(r,e));for(var u=[],i=[],o=0,a=n.length;a>o;o++){var c=n[o],l=r?r(c,o,n):c;t?(o&&i===l||u.push(c),i=l):r?m.contains(i,l)||(i.push(l),u.push(c)):m.contains(u,c)||u.push(c)}return u},m.union=function(){return m.uniq(k(arguments,!0,!0))},m.intersection=function(n){if(null==n)return[];for(var t=[],r=arguments.length,e=0,u=n.length;u>e;e++){var i=n[e];if(!m.contains(t,i)){for(var o=1;r>o&&m.contains(arguments[o],i);o++);o===r&&t.push(i)}}return t},m.difference=function(n){var t=k(arguments,!0,!0,1);return m.filter(n,function(n){return!m.contains(t,n)})},m.zip=function(){return m.unzip(arguments)},m.unzip=function(n){for(var t=n&&m.max(n,"length").length||0,r=Array(t),e=0;t>e;e++)r[e]=m.pluck(n,e);return r},m.object=function(n,t){for(var r={},e=0,u=n&&n.length;u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},m.indexOf=function(n,t,r){var e=0,u=n&&n.length;if("number"==typeof r)e=0>r?Math.max(0,u+r):r;else if(r&&u)return e=m.sortedIndex(n,t),n[e]===t?e:-1;if(t!==t)return m.findIndex(l.call(n,e),m.isNaN);for(;u>e;e++)if(n[e]===t)return e;return-1},m.lastIndexOf=function(n,t,r){var e=n?n.length:0;if("number"==typeof r&&(e=0>r?e+r+1:Math.min(e,r+1)),t!==t)return m.findLastIndex(l.call(n,0,e),m.isNaN);for(;--e>=0;)if(n[e]===t)return e;return-1},m.findIndex=t(1),m.findLastIndex=t(-1),m.sortedIndex=function(n,t,r,e){r=b(r,e,1);for(var u=r(t),i=0,o=n.length;o>i;){var a=Math.floor((i+o)/2);r(n[a])<u?i=a+1:o=a}return i},m.range=function(n,t,r){arguments.length<=1&&(t=n||0,n=0),r=r||1;for(var e=Math.max(Math.ceil((t-n)/r),0),u=Array(e),i=0;e>i;i++,n+=r)u[i]=n;return u};var O=function(n,t,r,e,u){if(!(e instanceof t))return n.apply(r,u);var i=_(n.prototype),o=n.apply(i,u);return m.isObject(o)?o:i};m.bind=function(n,t){if(v&&n.bind===v)return v.apply(n,l.call(arguments,1));if(!m.isFunction(n))throw new TypeError("Bind must be called on a function");var r=l.call(arguments,2),e=function(){return O(n,e,t,this,r.concat(l.call(arguments)))};return e},m.partial=function(n){var t=l.call(arguments,1),r=function(){for(var e=0,u=t.length,i=Array(u),o=0;u>o;o++)i[o]=t[o]===m?arguments[e++]:t[o];for(;e<arguments.length;)i.push(arguments[e++]);return O(n,r,this,this,i)};return r},m.bindAll=function(n){var t,r,e=arguments.length;if(1>=e)throw new Error("bindAll must be passed function names");for(t=1;e>t;t++)r=arguments[t],n[r]=m.bind(n[r],n);return n},m.memoize=function(n,t){var r=function(e){var u=r.cache,i=""+(t?t.apply(this,arguments):e);return m.has(u,i)||(u[i]=n.apply(this,arguments)),u[i]};return r.cache={},r},m.delay=function(n,t){var r=l.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},m.defer=m.partial(m.delay,m,1),m.throttle=function(n,t,r){var e,u,i,o=null,a=0;r||(r={});var c=function(){a=r.leading===!1?0:m.now(),o=null,i=n.apply(e,u),o||(e=u=null)};return function(){var l=m.now();a||r.leading!==!1||(a=l);var f=t-(l-a);return e=this,u=arguments,0>=f||f>t?(o&&(clearTimeout(o),o=null),a=l,i=n.apply(e,u),o||(e=u=null)):o||r.trailing===!1||(o=setTimeout(c,f)),i}},m.debounce=function(n,t,r){var e,u,i,o,a,c=function(){var l=m.now()-o;t>l&&l>=0?e=setTimeout(c,t-l):(e=null,r||(a=n.apply(i,u),e||(i=u=null)))};return function(){i=this,u=arguments,o=m.now();var l=r&&!e;return e||(e=setTimeout(c,t)),l&&(a=n.apply(i,u),i=u=null),a}},m.wrap=function(n,t){return m.partial(t,n)},m.negate=function(n){return function(){return!n.apply(this,arguments)}},m.compose=function(){var n=arguments,t=n.length-1;return function(){for(var r=t,e=n[t].apply(this,arguments);r--;)e=n[r].call(this,e);return e}},m.after=function(n,t){return function(){return--n<1?t.apply(this,arguments):void 0}},m.before=function(n,t){var r;return function(){return--n>0&&(r=t.apply(this,arguments)),1>=n&&(t=null),r}},m.once=m.partial(m.before,2);var F=!{toString:null}.propertyIsEnumerable("toString"),S=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"];m.keys=function(n){if(!m.isObject(n))return[];if(h)return h(n);var t=[];for(var e in n)m.has(n,e)&&t.push(e);return F&&r(n,t),t},m.allKeys=function(n){if(!m.isObject(n))return[];var t=[];for(var e in n)t.push(e);return F&&r(n,t),t},m.values=function(n){for(var t=m.keys(n),r=t.length,e=Array(r),u=0;r>u;u++)e[u]=n[t[u]];return e},m.mapObject=function(n,t,r){t=b(t,r);for(var e,u=m.keys(n),i=u.length,o={},a=0;i>a;a++)e=u[a],o[e]=t(n[e],e,n);return o},m.pairs=function(n){for(var t=m.keys(n),r=t.length,e=Array(r),u=0;r>u;u++)e[u]=[t[u],n[t[u]]];return e},m.invert=function(n){for(var t={},r=m.keys(n),e=0,u=r.length;u>e;e++)t[n[r[e]]]=r[e];return t},m.functions=m.methods=function(n){var t=[];for(var r in n)m.isFunction(n[r])&&t.push(r);return t.sort()},m.extend=x(m.allKeys),m.extendOwn=m.assign=x(m.keys),m.findKey=function(n,t,r){t=b(t,r);for(var e,u=m.keys(n),i=0,o=u.length;o>i;i++)if(e=u[i],t(n[e],e,n))return e},m.pick=function(n,t,r){var e,u,i={},o=n;if(null==o)return i;m.isFunction(t)?(u=m.allKeys(o),e=d(t,r)):(u=k(arguments,!1,!1,1),e=function(n,t,r){return t in r},o=Object(o));for(var a=0,c=u.length;c>a;a++){var l=u[a],f=o[l];e(f,l,o)&&(i[l]=f)}return i},m.omit=function(n,t,r){if(m.isFunction(t))t=m.negate(t);else{var e=m.map(k(arguments,!1,!1,1),String);t=function(n,t){return!m.contains(e,t)}}return m.pick(n,t,r)},m.defaults=x(m.allKeys,!0),m.clone=function(n){return m.isObject(n)?m.isArray(n)?n.slice():m.extend({},n):n},m.tap=function(n,t){return t(n),n},m.isMatch=function(n,t){var r=m.keys(t),e=r.length;if(null==n)return!e;for(var u=Object(n),i=0;e>i;i++){var o=r[i];if(t[o]!==u[o]||!(o in u))return!1}return!0};var E=function(n,t,r,e){if(n===t)return 0!==n||1/n===1/t;if(null==n||null==t)return n===t;n instanceof m&&(n=n._wrapped),t instanceof m&&(t=t._wrapped);var u=f.call(n);if(u!==f.call(t))return!1;switch(u){case"[object RegExp]":case"[object String]":return""+n==""+t;case"[object Number]":return+n!==+n?+t!==+t:0===+n?1/+n===1/t:+n===+t;case"[object Date]":case"[object Boolean]":return+n===+t}var i="[object Array]"===u;if(!i){if("object"!=typeof n||"object"!=typeof t)return!1;var o=n.constructor,a=t.constructor;if(o!==a&&!(m.isFunction(o)&&o instanceof o&&m.isFunction(a)&&a instanceof a)&&"constructor"in n&&"constructor"in t)return!1}r=r||[],e=e||[];for(var c=r.length;c--;)if(r[c]===n)return e[c]===t;if(r.push(n),e.push(t),i){if(c=n.length,c!==t.length)return!1;for(;c--;)if(!E(n[c],t[c],r,e))return!1}else{var l,s=m.keys(n);if(c=s.length,m.keys(t).length!==c)return!1;for(;c--;)if(l=s[c],!m.has(t,l)||!E(n[l],t[l],r,e))return!1}return r.pop(),e.pop(),!0};m.isEqual=function(n,t){return E(n,t)},m.isEmpty=function(n){return null==n?!0:w(n)&&(m.isArray(n)||m.isString(n)||m.isArguments(n))?0===n.length:0===m.keys(n).length},m.isElement=function(n){return!(!n||1!==n.nodeType)},m.isArray=p||function(n){return"[object Array]"===f.call(n)},m.isObject=function(n){var t=typeof n;return"function"===t||"object"===t&&!!n},m.each(["Arguments","Function","String","Number","Date","RegExp","Error"],function(n){m["is"+n]=function(t){return f.call(t)==="[object "+n+"]"}}),m.isArguments(arguments)||(m.isArguments=function(n){return m.has(n,"callee")}),"function"!=typeof/./&&"object"!=typeof Int8Array&&(m.isFunction=function(n){return"function"==typeof n||!1}),m.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},m.isNaN=function(n){return m.isNumber(n)&&n!==+n},m.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"===f.call(n)},m.isNull=function(n){return null===n},m.isUndefined=function(n){return n===void 0},m.has=function(n,t){return null!=n&&s.call(n,t)},m.noConflict=function(){return e._=u,this},m.identity=function(n){return n},m.constant=function(n){return function(){return n}},m.noop=function(){},m.property=function(n){return function(t){return null==t?void 0:t[n]}},m.propertyOf=function(n){return null==n?function(){}:function(t){return n[t]}},m.matcher=m.matches=function(n){return n=m.extendOwn({},n),function(t){return m.isMatch(t,n)}},m.times=function(n,t,r){var e=Array(Math.max(0,n));t=d(t,r,1);for(var u=0;n>u;u++)e[u]=t(u);return e},m.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))},m.now=Date.now||function(){return(new Date).getTime()};var M={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},N=m.invert(M),I=function(n){var t=function(t){return n[t]},r="(?:"+m.keys(n).join("|")+")",e=RegExp(r),u=RegExp(r,"g");return function(n){return n=null==n?"":""+n,e.test(n)?n.replace(u,t):n}};m.escape=I(M),m.unescape=I(N),m.result=function(n,t,r){var e=null==n?void 0:n[t];return e===void 0&&(e=r),m.isFunction(e)?e.call(n):e};var B=0;m.uniqueId=function(n){var t=++B+"";return n?n+t:t},m.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var T=/(.)^/,R={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},q=/\\|'|\r|\n|\u2028|\u2029/g,K=function(n){return"\\"+R[n]};m.template=function(n,t,r){!t&&r&&(t=r),t=m.defaults({},t,m.templateSettings);var e=RegExp([(t.escape||T).source,(t.interpolate||T).source,(t.evaluate||T).source].join("|")+"|$","g"),u=0,i="__p+='";n.replace(e,function(t,r,e,o,a){return i+=n.slice(u,a).replace(q,K),u=a+t.length,r?i+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'":e?i+="'+\n((__t=("+e+"))==null?'':__t)+\n'":o&&(i+="';\n"+o+"\n__p+='"),t}),i+="';\n",t.variable||(i="with(obj||{}){\n"+i+"}\n"),i="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+i+"return __p;\n";try{var o=new Function(t.variable||"obj","_",i)}catch(a){throw a.source=i,a}var c=function(n){return o.call(this,n,m)},l=t.variable||"obj";return c.source="function("+l+"){\n"+i+"}",c},m.chain=function(n){var t=m(n);return t._chain=!0,t};var z=function(n,t){return n._chain?m(t).chain():t};m.mixin=function(n){m.each(m.functions(n),function(t){var r=m[t]=n[t];m.prototype[t]=function(){var n=[this._wrapped];return c.apply(n,arguments),z(this,r.apply(m,n))}})},m.mixin(m),m.each(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=i[n];m.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!==n&&"splice"!==n||0!==r.length||delete r[0],z(this,r)}}),m.each(["concat","join","slice"],function(n){var t=i[n];m.prototype[n]=function(){return z(this,t.apply(this._wrapped,arguments))}}),m.prototype.value=function(){return this._wrapped},m.prototype.valueOf=m.prototype.toJSON=m.prototype.value,m.prototype.toString=function(){return""+this._wrapped},"function"==typeof define&&define.amd&&define("underscore",[],function(){return m})}).call(this);
     6//# sourceMappingURL=underscore-min.map
  • src/wp-includes/script-loader.php

     
    293293        $scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", array(), '2011-02-23' );
    294294        did_action( 'init' ) && $scripts->add_data( 'json2', 'conditional', 'lt IE 8' );
    295295
    296         $scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.6.0', 1 );
     296        $scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.8.2', 1 );
    297297        $scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore','jquery' ), '1.1.2', 1 );
    298298
    299299        $scripts->add( 'wp-util', "/wp-includes/js/wp-util$suffix.js", array('underscore', 'jquery'), false, 1 );