JAVASCRIPT 382
Underscore.js Guest on 17th April 2021 01:15:00 PM
  1. //     Underscore.js 1.7.0
  2. //     http://underscorejs.org
  3. //     (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  4. //     Underscore may be freely distributed under the MIT license.
  5.  
  6. (function() {
  7.  
  8.   // Baseline setup
  9.   // --------------
  10.  
  11.   // Establish the root object, `window` in the browser, or `exports` on the server.
  12.   var root = this;
  13.  
  14.   // Save the previous value of the `_` variable.
  15.   var previousUnderscore = root._;
  16.  
  17.   // Save bytes in the minified (but not gzipped) version:
  18.   var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
  19.  
  20.   // Create quick reference variables for speed access to core prototypes.
  21.   var
  22.     push             = ArrayProto.push,
  23.     slice            = ArrayProto.slice,
  24.     concat           = ArrayProto.concat,
  25.     toString         = ObjProto.toString,
  26.     hasOwnProperty   = ObjProto.hasOwnProperty;
  27.  
  28.   // All **ECMAScript 5** native function implementations that we hope to use
  29.   // are declared here.
  30.   var
  31.     nativeIsArray      = Array.isArray,
  32.     nativeKeys         = Object.keys,
  33.     nativeBind         = FuncProto.bind;
  34.  
  35.   // Create a safe reference to the Underscore object for use below.
  36.   var _ = function(obj) {
  37.     if (obj instanceof _) return obj;
  38.     if (!(this instanceof _)) return new _(obj);
  39.     this._wrapped = obj;
  40.   };
  41.  
  42.   // Export the Underscore object for **Node.js**, with
  43.   // backwards-compatibility for the old `require()` API. If we're in
  44.   // the browser, add `_` as a global object.
  45.   if (typeof exports !== 'undefined') {
  46.     if (typeof module !== 'undefined' && module.exports) {
  47.       exports = module.exports = _;
  48.     }
  49.     exports._ = _;
  50.   } else {
  51.     root._ = _;
  52.   }
  53.  
  54.   // Current version.
  55.   _.VERSION = '1.7.0';
  56.  
  57.   // Internal function that returns an efficient (for current engines) version
  58.   // of the passed-in callback, to be repeatedly applied in other Underscore
  59.   // functions.
  60.   var createCallback = function(func, context, argCount) {
  61.     if (context === void 0) return func;
  62.     switch (argCount == null ? 3 : argCount) {
  63.       case 1: return function(value) {
  64.         return func.call(context, value);
  65.       };
  66.       case 2: return function(value, other) {
  67.         return func.call(context, value, other);
  68.       };
  69.       case 3: return function(value, index, collection) {
  70.         return func.call(context, value, index, collection);
  71.       };
  72.       case 4: return function(accumulator, value, index, collection) {
  73.         return func.call(context, accumulator, value, index, collection);
  74.       };
  75.     }
  76.     return function() {
  77.       return func.apply(context, arguments);
  78.     };
  79.   };
  80.  
  81.   // A mostly-internal function to generate callbacks that can be applied
  82.   // to each element in a collection, returning the desired result ā€” either
  83. th// identity, an arbitrary callback, a property matcher, or a property accessor.
  84. sor.
  85.   _.iteratee = function(value, context, argCount) {
  86.     if (value == null) return _.identity;
  87.     if (_.isFunction(value)) return createCallback(value, context, argCount);
  88.     if (_.isObject(value)) return _.matches(value);
  89.     return _.property(value);
  90.   }// Collection Functions
  91. io// --------------------
  92. ---// The cornerstone, an `each` implementation, aka `forEach`.
  93. ch// Handles raw objects in addition to array-likes. Treats all
  94.  a// sparse array-likes as if they were dense.
  95. nse.
  96.   _.each = _.forEach = function(obj, iteratee, context) {
  97.     if (obj == null) return obj;
  98.     iteratee = createCallback(iteratee, context);
  99.     var i, length = obj.length;
  100.     if (length === +length) {
  101.       for (i = 0; i < length; i++) {
  102.         iteratee(obj[i], i, obj);
  103.       }
  104.     } else {
  105.       var keys = _.keys(obj);
  106.       for (i = 0, length = keys.length; i < length; i++) {
  107.         iteratee(obj[keys[i]], keys[i], obj);
  108.       }
  109.     }
  110.     return obj;
  111.   }// Return the results of applying the iteratee to each element.
  112. ent.
  113.   _.map = _.collect = function(obj, iteratee, context) {
  114.     if (obj == null) return [];
  115.     iteratee = _.iteratee(iteratee, context);
  116.     var keys = obj.length !== +obj.length && _.keys(obj),
  117.         length = (keys || obj).length,
  118.         results = Array(length),
  119.         currentKey;
  120.     for (var index = 0; index < length; index++) {
  121.       currentKey = keys ? keys[index] : index;
  122.       results[index] = iteratee(obj[currentKey], currentKey, obj);
  123.     }
  124.     return results;
  125.   };
  126.  
  127.   var reduceError = 'Reduce of empty array with no initial value'// **Reduce** builds up a single result from a list of values, aka `inject`,
  128. ct// or `foldl`.
  129. dl`.
  130.   _.reduce = _.foldl = _.inject = function(obj, iteratee, memo, context) {
  131.     if (obj == null) obj = [];
  132.     iteratee = createCallback(iteratee, context, 4);
  133.     var keys = obj.length !== +obj.length && _.keys(obj),
  134.         length = (keys || obj).length,
  135.         index = 0, currentKey;
  136.     if (arguments.length < 3) {
  137.       if (!length) throw new TypeError(reduceError);
  138.       memo = obj[keys ? keys[index++] : index++];
  139.     }
  140.     for (; index < length; index++) {
  141.       currentKey = keys ? keys[index] : index;
  142.       memo = iteratee(memo, obj[currentKey], currentKey, obj);
  143.     }
  144.     return memo;
  145.   }// The right-associative version of reduce, also known as `foldr`.
  146. dr`.
  147.   _.reduceRight = _.foldr = function(obj, iteratee, memo, context) {
  148.     if (obj == null) obj = [];
  149.     iteratee = createCallback(iteratee, context, 4);
  150.     var keys = obj.length !== + obj.length && _.keys(obj),
  151.         index = (keys || obj).length,
  152.         currentKey;
  153.     if (arguments.length < 3) {
  154.       if (!index) throw new TypeError(reduceError);
  155.       memo = obj[keys ? keys[--index] : --index];
  156.     }
  157.     while (index--) {
  158.       currentKey = keys ? keys[index] : index;
  159.       memo = iteratee(memo, obj[currentKey], currentKey, obj);
  160.     }
  161.     return memo;
  162.   }// Return the first value which passes a truth test. Aliased as `detect`.
  163. ct`.
  164.   _.find = _.detect = function(obj, predicate, context) {
  165.     var result;
  166.     predicate = _.iteratee(predicate, context);
  167.     _.some(obj, function(value, index, list) {
  168.       if (predicate(value, index, list)) {
  169.         result = value;
  170.         return true;
  171.       }
  172.     });
  173.     return result;
  174.   }// Return all the elements that pass a truth test.
  175. es// Aliased as `select`.
  176. ct`.
  177.   _.filter = _.select = function(obj, predicate, context) {
  178.     var results = [];
  179.     if (obj == null) return results;
  180.     predicate = _.iteratee(predicate, context);
  181.     _.each(obj, function(value, index, list) {
  182.       if (predicate(value, index, list)) results.push(value);
  183.     });
  184.     return results;
  185.   }// Return all the elements for which a truth test fails.
  186. ils.
  187.   _.reject = function(obj, predicate, context) {
  188.     return _.filter(obj, _.negate(_.iteratee(predicate)), context);
  189.   }// Determine whether all of the elements match a truth test.
  190. es// Aliased as `all`.
  191. ll`.
  192.   _.every = _.all = function(obj, predicate, context) {
  193.     if (obj == null) return true;
  194.     predicate = _.iteratee(predicate, context);
  195.     var keys = obj.length !== +obj.length && _.keys(obj),
  196.         length = (keys || obj).length,
  197.         index, currentKey;
  198.     for (index = 0; index < length; index++) {
  199.       currentKey = keys ? keys[index] : index;
  200.       if (!predicate(obj[currentKey], currentKey, obj)) return false;
  201.     }
  202.     return true;
  203.   }// Determine if at least one element in the object matches a truth test.
  204. es// Aliased as `any`.
  205. ny`.
  206.   _.some = _.any = function(obj, predicate, context) {
  207.     if (obj == null) return false;
  208.     predicate = _.iteratee(predicate, context);
  209.     var keys = obj.length !== +obj.length && _.keys(obj),
  210.         length = (keys || obj).length,
  211.         index, currentKey;
  212.     for (index = 0; index < length; index++) {
  213.       currentKey = keys ? keys[index] : index;
  214.       if (predicate(obj[currentKey], currentKey, obj)) return true;
  215.     }
  216.     return false;
  217.   }// Determine if the array or object contains a given value (using `===`).
  218. =`// Aliased as `include`.
  219. de`.
  220.   _.contains = _.include = function(obj, target) {
  221.     if (obj == null) return false;
  222.     if (obj.length !== +obj.length) obj = _.values(obj);
  223.     return _.indexOf(obj, target) >= 0;
  224.   }// Invoke a method (with arguments) on every item in a collection.
  225. ion.
  226.   _.invoke = function(obj, method) {
  227.     var args = slice.call(arguments, 2);
  228.     var isFunc = _.isFunction(method);
  229.     return _.map(obj, function(value) {
  230.       return (isFunc ? method : value[method]).apply(value, args);
  231.     });
  232.   }// Convenience version of a common use case of `map`: fetching a property.
  233. rty.
  234.   _.pluck = function(obj, key) {
  235.     return _.map(obj, _.property(key));
  236.   }// Convenience version of a common use case of `filter`: selecting only objects
  237. ec// containing specific `key:value` pairs.
  238. irs.
  239.   _.where = function(obj, attrs) {
  240.     return _.filter(obj, _.matches(attrs));
  241.   }// Convenience version of a common use case of `find`: getting the first object
  242. je// containing specific `key:value` pairs.
  243. irs.
  244.   _.findWhere = function(obj, attrs) {
  245.     return _.find(obj, _.matches(attrs));
  246.   }// Return the maximum element (or element-based computation).
  247. on).
  248.   _.max = function(obj, iteratee, context) {
  249.     var result = -Infinity, lastComputed = -Infinity,
  250.         value, computed;
  251.     if (iteratee == null && obj != null) {
  252.       obj = obj.length === +obj.length ? obj : _.values(obj);
  253.       for (var i = 0, length = obj.length; i < length; i++) {
  254.         value = obj[i];
  255.         if (value > result) {
  256.           result = value;
  257.         }
  258.       }
  259.     } else {
  260.       iteratee = _.iteratee(iteratee, context);
  261.       _.each(obj, function(value, index, list) {
  262.         computed = iteratee(value, index, list);
  263.         if (computed > lastComputed || computed === -Infinity && result === -Infinity) {
  264.           result = value;
  265.           lastComputed = computed;
  266.         }
  267.       });
  268.     }
  269.     return result;
  270.   }// Return the minimum element (or element-based computation).
  271. on).
  272.   _.min = function(obj, iteratee, context) {
  273.     var result = Infinity, lastComputed = Infinity,
  274.         value, computed;
  275.     if (iteratee == null && obj != null) {
  276.       obj = obj.length === +obj.length ? obj : _.values(obj);
  277.       for (var i = 0, length = obj.length; i < length; i++) {
  278.         value = obj[i];
  279.         if (value < result) {
  280.           result = value;
  281.         }
  282.       }
  283.     } else {
  284.       iteratee = _.iteratee(iteratee, context);
  285.       _.each(obj, function(value, index, list) {
  286.         computed = iteratee(value, index, list);
  287.         if (computed < lastComputed || computed === Infinity && result === Infinity) {
  288.           result = value;
  289.           lastComputed = computed;
  290.         }
  291.       });
  292.     }
  293.     return result;
  294.   }// Shuffle a collection, using the modern version of the
  295.  t// [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisherā€“Yates_shuffle).
  296. shuffle).
  297.   _.shuffle = function(obj) {
  298.     var set = obj && obj.length === +obj.length ? obj : _.values(obj);
  299.     var length = set.length;
  300.     var shuffled = Array(length);
  301.     for (var index = 0, rand; index < length; index++) {
  302.       rand = _.random(0, index);
  303.       if (rand !== index) shuffled[index] = shuffled[rand];
  304.       shuffled[rand] = set[index];
  305.     }
  306.     return shuffled// Sample **n** random values from a collection.
  307. ll// If **n** is not specified, returns a single random element.
  308.  e// The internal `guard` argument allows it to work with `map`.
  309. th `map`.
  310.   _.sample = function(obj, n, guard) {
  311.     if (n == null || guard) {
  312.       if (obj.length !== +obj.length) obj = _.values(obj);
  313.       return obj[_.random(obj.length - 1)];
  314.     }
  315.     return _.shuffle(obj).slice(0, Math.max(0, n))// Sort the object's values by a criterion produced by an iteratee.
  316. iteratee.
  317.   _.sortBy = function(obj, iteratee, context) {
  318.     iteratee = _.iteratee(iteratee, context);
  319.     return _.pluck(_.map(obj, function(value, index, list) {
  320.       return {
  321.         value: value,
  322.         index: index,
  323.         criteria: iteratee(value, index, list)
  324.       };
  325.     }).sort(function(left, right) {
  326.       var a = left.criteria;
  327.       var b = right.criteria;
  328.       if (a !== b) {
  329.         if (a > b || a === void 0) return 1;
  330.         if (a < b || b === void 0) return -1;
  331.       }
  332.       return left.index - right.index;
  333.     }), 'value')// An internal function used for aggregate "group by" operations.
  334. erations.
  335.   var group = function(behavior) {
  336.     return function(obj, iteratee, context) {
  337.       var result = {};
  338.       iteratee = _.iteratee(iteratee, context);
  339.       _.each(obj, function(value, index) {
  340.         var key = iteratee(value, index, obj);
  341.         behavior(result, value, key);
  342.       });
  343.       return result;
  344.     }// Groups the object's values by a criterion. Pass either a string attribute
  345. at// to group by, or a function that returns the criterion.
  346. riterion.
  347.   _.groupBy = group(function(result, value, key) {
  348.     if (_.has(result, key)) result[key].push(value); else result[key] = [value];// Indexes the object's values by a criterion, similar to `groupBy`, but for
  349. , // when you know that your index values will be unique.
  350. e unique.
  351.   _.indexBy = group(function(result, value, key) {
  352.     result[key] = value;// Counts instances of an object that group by a certain criterion. Pass
  353. io// either a string attribute to count by, or a function that returns the
  354. tu// criterion.
  355. riterion.
  356.   _.countBy = group(function(result, value, key) {
  357.     if (_.has(result, key)) result[key]++; else result[key] = 1;// Use a comparator function to figure out the smallest index at which
  358.  a// an object should be inserted so as to maintain order. Uses binary search.
  359. y search.
  360.   _.sortedIndex = function(array, obj, iteratee, context) {
  361.     iteratee = _.iteratee(iteratee, context, 1);
  362.     var value = iteratee(obj);
  363.     var low = 0, high = array.length;
  364.     while (low < high) {
  365.       var mid = low + high >>> 1;
  366.       if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
  367.     }
  368.     return low// Safely create a real, live array from anything iterable.
  369. iterable.
  370.   _.toArray = function(obj) {
  371.     if (!obj) return [];
  372.     if (_.isArray(obj)) return slice.call(obj);
  373.     if (obj.length === +obj.length) return _.map(obj, _.identity);
  374.     return _.values(obj)// Return the number of elements in an object.
  375. n object.
  376.   _.size = function(obj) {
  377.     if (obj == null) return 0;
  378.     return obj.length === +obj.length ? obj.length : _.keys(obj).length// Split a collection into two arrays: one whose elements all satisfy the given
  379. th// predicate, and one whose elements all do not satisfy the predicate.
  380. redicate.
  381.   _.partition = function(obj, predicate, context) {
  382.     predicate = _.iteratee(predicate, context);
  383.     var pass = [], fail = [];
  384.     _.each(obj, function(value, key, obj) {
  385.       (predicate(value, key, obj) ? pass : fail).push(value);
  386.     });
  387.     return [pass, fail]// Array Functions
  388. Fu// ---------------
  389. ---// Get the first element of an array. Passing **n** will return the first N
  390. e // values in the array. Aliased as `head` and `take`. The **guard** check
  391. d*// allows it to work with `_.map`.
  392.  `_.map`.
  393.   _.first = _.head = _.take = function(array, n, guard) {
  394.     if (array == null) return void 0;
  395.     if (n == null || guard) return array[0];
  396.     if (n < 0) return [];
  397.     return slice.call(array, 0, n)// Returns everything but the last entry of the array. Especially useful on
  398. us// the arguments object. Passing **n** will return all the values in
  399. va// the array, excluding the last N. The **guard** check allows it to work with
  400. wo// `_.map`.
  401.  `_.map`.
  402.   _.initial = function(array, n, guard) {
  403.     return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)))// Get the last element of an array. Passing **n** will return the last N
  404. he// values in the array. The **guard** check allows it to work with `_.map`.
  405.  `_.map`.
  406.   _.last = function(array, n, guard) {
  407.     if (array == null) return void 0;
  408.     if (n == null || guard) return array[array.length - 1];
  409.     return slice.call(array, Math.max(array.length - n, 0))// Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
  410. d // Especially useful on the arguments object. Passing an **n** will return
  411. ll// the rest N values in the array. The **guard**
  412. **// check allows it to work with `_.map`.
  413.  `_.map`.
  414.   _.rest = _.tail = _.drop = function(array, n, guard) {
  415.     return slice.call(array, n == null || guard ? 1 : n)// Trim out all falsy values from an array.
  416. an array.
  417.   _.compact = function(array) {
  418.     return _.filter(array, _.identity)// Internal implementation of a recursive `flatten` function.
  419. function.
  420.   var flatten = function(input, shallow, strict, output) {
  421.     if (shallow && _.every(input, _.isArray)) {
  422.       return concat.apply(output, input);
  423.     }
  424.     for (var i = 0, length = input.length; i < length; i++) {
  425.       var value = input[i];
  426.       if (!_.isArray(value) && !_.isArguments(value)) {
  427.         if (!strict) output.push(value);
  428.       } else if (shallow) {
  429.         push.apply(output, value);
  430.       } else {
  431.         flatten(value, shallow, strict, output);
  432.       }
  433.     }
  434.     return output// Flatten out an array, either recursively (by default), or just one level.
  435. ne level.
  436.   _.flatten = function(array, shallow) {
  437.     return flatten(array, shallow, false, [])// Return a version of the array that does not contain the specified value(s).
  438. value(s).
  439.   _.without = function(array) {
  440.     return _.difference(array, slice.call(arguments, 1))// Produce a duplicate-free version of the array. If the array has already
  441. s // been sorted, you have the option of using a faster algorithm.
  442. lg// Aliased as `unique`.
  443. `unique`.
  444.   _.uniq = _.unique = function(array, isSorted, iteratee, context) {
  445.     if (array == null) return [];
  446.     if (!_.isBoolean(isSorted)) {
  447.       context = iteratee;
  448.       iteratee = isSorted;
  449.       isSorted = false;
  450.     }
  451.     if (iteratee != null) iteratee = _.iteratee(iteratee, context);
  452.     var result = [];
  453.     var seen = [];
  454.     for (var i = 0, length = array.length; i < length; i++) {
  455.       var value = array[i];
  456.       if (isSorted) {
  457.         if (!i || seen !== value) result.push(value);
  458.         seen = value;
  459.       } else if (iteratee) {
  460.         var computed = iteratee(value, i, array);
  461.         if (_.indexOf(seen, computed) < 0) {
  462.           seen.push(computed);
  463.           result.push(value);
  464.         }
  465.       } else if (_.indexOf(result, value) < 0) {
  466.         result.push(value);
  467.       }
  468.     }
  469.     return result// Produce an array that contains the union: each distinct element from all of
  470. om// the passed-in arrays.
  471. n arrays.
  472.   _.union = function() {
  473.     return _.uniq(flatten(arguments, true, true, []))// Produce an array that contains every item shared between all the
  474. n // passed-in arrays.
  475. n arrays.
  476.   _.intersection = function(array) {
  477.     if (array == null) return [];
  478.     var result = [];
  479.     var argsLength = arguments.length;
  480.     for (var i = 0, length = array.length; i < length; i++) {
  481.       var item = array[i];
  482.       if (_.contains(result, item)) continue;
  483.       for (var j = 1; j < argsLength; j++) {
  484.         if (!_.contains(arguments[j], item)) break;
  485.       }
  486.       if (j === argsLength) result.push(item);
  487.     }
  488.     return result// Take the difference between one array and a number of other arrays.
  489. r // Only the elements present in just the first array will remain.
  490. l remain.
  491.   _.difference = function(array) {
  492.     var rest = flatten(slice.call(arguments, 1), true, true, []);
  493.     return _.filter(array, function(value){
  494.       return !_.contains(rest, value);
  495.     })// Zip together multiple lists into a single array -- elements that share
  496. ha// an index go together.
  497. together.
  498.   _.zip = function(array) {
  499.     if (array == null) return [];
  500.     var length = _.max(arguments, 'length').length;
  501.     var results = Array(length);
  502.     for (var i = 0; i < length; i++) {
  503.       results[i] = _.pluck(arguments, i);
  504.     }
  505.     return results// Converts lists into objects. Pass either a single array of `[key, value]`
  506. , // pairs, or two parallel arrays of the same length -- one of keys, and one of
  507. nd// the corresponding values.
  508. g values.
  509.   _.object = function(list, values) {
  510.     if (list == null) return {};
  511.     var result = {};
  512.     for (var i = 0, length = list.length; i < length; i++) {
  513.       if (values) {
  514.         result[list[i]] = values[i];
  515.       } else {
  516.         result[list[i][0]] = list[i][1];
  517.       }
  518.     }
  519.     return result// Return the position of the first occurrence of an item in an array,
  520. an// or -1 if the item is not included in the array.
  521. he// If the array is large and already in sort order, pass `true`
  522. ss// for **isSorted** to use binary search.
  523. y search.
  524.   _.indexOf = function(array, item, isSorted) {
  525.     if (array == null) return -1;
  526.     var i = 0, length = array.length;
  527.     if (isSorted) {
  528.       if (typeof isSorted == 'number') {
  529.         i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted;
  530.       } else {
  531.         i = _.sortedIndex(array, item);
  532.         return array[i] === item ? i : -1;
  533.       }
  534.     }
  535.     for (; i < length; i++) if (array[i] === item) return i;
  536.     return -1;
  537.   };
  538.  
  539.   _.lastIndexOf = function(array, item, from) {
  540.     if (array == null) return -1;
  541.     var idx = array.length;
  542.     if (typeof from == 'number') {
  543.       idx = from < 0 ? idx + from + 1 : Math.min(idx, from + 1);
  544.     }
  545.     while (--idx >= 0) if (array[idx] === item) return idx;
  546.     return -1// Generate an integer Array containing an arithmetic progression. A port of
  547. A // the native Python `range()` function. See
  548. ti// [the Python documentation](http://docs.python.org/library/functions.html#range).
  549. l#range).
  550.   _.range = function(start, stop, step) {
  551.     if (arguments.length <= 1) {
  552.       stop = start || 0;
  553.       start = 0;
  554.     }
  555.     step = step || 1;
  556.  
  557.     var length = Math.max(Math.ceil((stop - start) / step), 0);
  558.     var range = Array(length);
  559.  
  560.     for (var idx = 0; idx < length; idx++, start += step) {
  561.       range[idx] = start;
  562.     }
  563.  
  564.     return range// Function (ahem) Functions
  565. Fu// ------------------
  566. ---// Reusable constructor function for prototype setting.
  567.  setting.
  568.   var Ctor = functio// Create a function bound to a given object (assigning `this`, and arguments,
  569. rg// optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
  570. .b// available.
  571. vailable.
  572.   _.bind = function(func, context) {
  573.     var args, bound;
  574.     if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
  575.     if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function');
  576.     args = slice.call(arguments, 2);
  577.     bound = function() {
  578.       if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
  579.       Ctor.prototype = func.prototype;
  580.       var self = new Ctor;
  581.       Ctor.prototype = null;
  582.       var result = func.apply(self, args.concat(slice.call(arguments)));
  583.       if (_.isObject(result)) return result;
  584.       return self;
  585.     };
  586.     return bound// Partially apply a function by creating a version that has had some of its
  587. me// arguments pre-filled, without changing its dynamic `this` context. _ acts
  588. t.// as a placeholder, allowing any combination of arguments to be pre-filled.
  589. e-filled.
  590.   _.partial = function(func) {
  591.     var boundArgs = slice.call(arguments, 1);
  592.     return function() {
  593.       var position = 0;
  594.       var args = boundArgs.slice();
  595.       for (var i = 0, length = args.length; i < length; i++) {
  596.         if (args[i] === _) args[i] = arguments[position++];
  597.       }
  598.       while (position < arguments.length) args.push(arguments[position++]);
  599.       return func.apply(this, args);
  600.     }// Bind a number of an object's methods to that object. Remaining arguments
  601. ar// are the method names to be bound. Useful for ensuring that all callbacks
  602. ca// defined on an object belong to it.
  603. ng to it.
  604.   _.bindAll = function(obj) {
  605.     var i, length = arguments.length, key;
  606.     if (length <= 1) throw new Error('bindAll must be passed function names');
  607.     for (i = 1; i < length; i++) {
  608.       key = arguments[i];
  609.       obj[key] = _.bind(obj[key], obj);
  610.     }
  611.     return obj// Memoize an expensive function by storing its results.
  612.  results.
  613.   _.memoize = function(func, hasher) {
  614.     var memoize = function(key) {
  615.       var cache = memoize.cache;
  616.       var address = hasher ? hasher.apply(this, arguments) : key;
  617.       if (!_.has(cache, address)) cache[address] = func.apply(this, arguments);
  618.       return cache[address];
  619.     };
  620.     memoize.cache = {};
  621.     return memoize// Delays a function for the given number of milliseconds, and then calls
  622. he// it with the arguments supplied.
  623. supplied.
  624.   _.delay = function(func, wait) {
  625.     var args = slice.call(arguments, 2);
  626.     return setTimeout(function(){
  627.       return func.apply(null, args);
  628.     }, wait)// Defers a function, scheduling it to run after the current call stack has
  629. st// cleared.
  630.  cleared.
  631.   _.defer = function(func) {
  632.     return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)))// Returns a function, that, when invoked, will only be triggered at most once
  633. mo// during a given window of time. Normally, the throttled function will run
  634.  w// as much as it can, without ever going more than once per `wait` duration;
  635. du// but if you'd like to disable the execution on the leading edge, pass
  636. dg// `{leading: false}`. To disable execution on the trailing edge, ditto.
  637. e, ditto.
  638.   _.throttle = function(func, wait, options) {
  639.     var context, args, result;
  640.     var timeout = null;
  641.     var previous = 0;
  642.     if (!options) options = {};
  643.     var later = function() {
  644.       previous = options.leading === false ? 0 : _.now();
  645.       timeout = null;
  646.       result = func.apply(context, args);
  647.       if (!timeout) context = args = null;
  648.     };
  649.     return function() {
  650.       var now = _.now();
  651.       if (!previous && options.leading === false) previous = now;
  652.       var remaining = wait - (now - previous);
  653.       context = this;
  654.       args = arguments;
  655.       if (remaining <= 0 || remaining > wait) {
  656.         clearTimeout(timeout);
  657.         timeout = null;
  658.         previous = now;
  659.         result = func.apply(context, args);
  660.         if (!timeout) context = args = null;
  661.       } else if (!timeout && options.trailing !== false) {
  662.         timeout = setTimeout(later, remaining);
  663.       }
  664.       return result;
  665.     }// Returns a function, that, as long as it continues to be invoked, will not
  666.  w// be triggered. The function will be called after it stops being called for
  667. al// N milliseconds. If `immediate` is passed, trigger the function on the
  668. on// leading edge, instead of the trailing.
  669. trailing.
  670.   _.debounce = function(func, wait, immediate) {
  671.     var timeout, args, context, timestamp, result;
  672.  
  673.     var later = function() {
  674.       var last = _.now() - timestamp;
  675.  
  676.       if (last < wait && last > 0) {
  677.         timeout = setTimeout(later, wait - last);
  678.       } else {
  679.         timeout = null;
  680.         if (!immediate) {
  681.           result = func.apply(context, args);
  682.           if (!timeout) context = args = null;
  683.         }
  684.       }
  685.     };
  686.  
  687.     return function() {
  688.       context = this;
  689.       args = arguments;
  690.       timestamp = _.now();
  691.       var callNow = immediate && !timeout;
  692.       if (!timeout) timeout = setTimeout(later, wait);
  693.       if (callNow) {
  694.         result = func.apply(context, args);
  695.         context = args = null;
  696.       }
  697.  
  698.       return result;
  699.     }// Returns the first function passed as an argument to the second,
  700. e // allowing you to adjust arguments, run code before and after, and
  701. ft// conditionally execute the original function.
  702. function.
  703.   _.wrap = function(func, wrapper) {
  704.     return _.partial(wrapper, func)// Returns a negated version of the passed-in predicate.
  705. redicate.
  706.   _.negate = function(predicate) {
  707.     return function() {
  708.       return !predicate.apply(this, arguments);
  709.     }// Returns a function that is the composition of a list of functions, each
  710. on// consuming the return value of the function that follows.
  711.  follows.
  712.   _.compose = function() {
  713.     var args = arguments;
  714.     var start = args.length - 1;
  715.     return function() {
  716.       var i = start;
  717.       var result = args[start].apply(this, arguments);
  718.       while (i--) result = args[i].call(this, result);
  719.       return result;
  720.     }// Returns a function that will only be executed after being called N times.
  721.  N times.
  722.   _.after = function(times, func) {
  723.     return function() {
  724.       if (--times < 1) {
  725.         return func.apply(this, arguments);
  726.       }
  727.     }// Returns a function that will only be executed before being called N times.
  728.  N times.
  729.   _.before = function(times, func) {
  730.     var memo;
  731.     return function() {
  732.       if (--times > 0) {
  733.         memo = func.apply(this, arguments);
  734.       } else {
  735.         func = null;
  736.       }
  737.       return memo;
  738.     }// Returns a function that will be executed at most one time, no matter how
  739. at// often you call it. Useful for lazy initialization.
  740. lization.
  741.   _.once = _.partial(_.befor// Object Functions
  742. Fu// ----------------
  743. ---// Retrieve the names of an object's properties.
  744. op// Delegates to **ECMAScript 5**'s native `Object.keys`
  745. ect.keys`
  746.   _.keys = function(obj) {
  747.     if (!_.isObject(obj)) return [];
  748.     if (nativeKeys) return nativeKeys(obj);
  749.     var keys = [];
  750.     for (var key in obj) if (_.has(obj, key)) keys.push(key);
  751.     return keys// Retrieve the values of an object's properties.
  752. operties.
  753.   _.values = function(obj) {
  754.     var keys = _.keys(obj);
  755.     var length = keys.length;
  756.     var values = Array(length);
  757.     for (var i = 0; i < length; i++) {
  758.       values[i] = obj[keys[i]];
  759.     }
  760.     return values// Convert an object into a list of `[key, value]` pairs.
  761. ]` pairs.
  762.   _.pairs = function(obj) {
  763.     var keys = _.keys(obj);
  764.     var length = keys.length;
  765.     var pairs = Array(length);
  766.     for (var i = 0; i < length; i++) {
  767.       pairs[i] = [keys[i], obj[keys[i]]];
  768.     }
  769.     return pairs// Invert the keys and values of an object. The values must be serializable.
  770. alizable.
  771.   _.invert = function(obj) {
  772.     var result = {};
  773.     var keys = _.keys(obj);
  774.     for (var i = 0, length = keys.length; i < length; i++) {
  775.       result[obj[keys[i]]] = keys[i];
  776.     }
  777.     return result// Return a sorted list of the function names available on the object.
  778. e // Aliased as `methods`
  779. `methods`
  780.   _.functions = _.methods = function(obj) {
  781.     var names = [];
  782.     for (var key in obj) {
  783.       if (_.isFunction(obj[key])) names.push(key);
  784.     }
  785.     return names.sort()// Extend a given object with all the properties in passed-in object(s).
  786. bject(s).
  787.   _.extend = function(obj) {
  788.     if (!_.isObject(obj)) return obj;
  789.     var source, prop;
  790.     for (var i = 1, length = arguments.length; i < length; i++) {
  791.       source = arguments[i];
  792.       for (prop in source) {
  793.         if (hasOwnProperty.call(source, prop)) {
  794.             obj[prop] = source[prop];
  795.         }
  796.       }
  797.     }
  798.     return obj// Return a copy of the object only containing the whitelisted properties.
  799. operties.
  800.   _.pick = function(obj, iteratee, context) {
  801.     var result = {}, key;
  802.     if (obj == null) return result;
  803.     if (_.isFunction(iteratee)) {
  804.       iteratee = createCallback(iteratee, context);
  805.       for (key in obj) {
  806.         var value = obj[key];
  807.         if (iteratee(value, key, obj)) result[key] = value;
  808.       }
  809.     } else {
  810.       var keys = concat.apply([], slice.call(arguments, 1));
  811.       obj = new Object(obj);
  812.       for (var i = 0, length = keys.length; i < length; i++) {
  813.         key = keys[i];
  814.         if (key in obj) result[key] = obj[key];
  815.       }
  816.     }
  817.     return result;// Return a copy of the object without the blacklisted properties.
  818. operties.
  819.   _.omit = function(obj, iteratee, context) {
  820.     if (_.isFunction(iteratee)) {
  821.       iteratee = _.negate(iteratee);
  822.     } else {
  823.       var keys = _.map(concat.apply([], slice.call(arguments, 1)), String);
  824.       iteratee = function(value, key) {
  825.         return !_.contains(keys, key);
  826.       };
  827.     }
  828.     return _.pick(obj, iteratee, context)// Fill in a given object with default properties.
  829. operties.
  830.   _.defaults = function(obj) {
  831.     if (!_.isObject(obj)) return obj;
  832.     for (var i = 1, length = arguments.length; i < length; i++) {
  833.       var source = arguments[i];
  834.       for (var prop in source) {
  835.         if (obj[prop] === void 0) obj[prop] = source[prop];
  836.       }
  837.     }
  838.     return obj// Create a (shallow-cloned) duplicate of an object.
  839. n object.
  840.   _.clone = function(obj) {
  841.     if (!_.isObject(obj)) return obj;
  842.     return _.isArray(obj) ? obj.slice() : _.extend({}, obj)// Invokes interceptor with the obj, and then returns obj.
  843. ur// The primary purpose of this method is to "tap into" a method chain, in
  844. ch// order to perform operations on intermediate results within the chain.
  845. he chain.
  846.   _.tap = function(obj, interceptor) {
  847.     interceptor(obj);
  848.     return obj// Internal recursive comparison function for `isEqual`.
  849. isEqual`.
  850.   var eq = function(a, b, aStack, bSta// Identical objects are equal. `0 === -0`, but they aren't identical.
  851. dent// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
  852. ny:egal).
  853.     if (a === b) return a !== 0 || 1 / a === 1// A strict comparison is necessary because `null == undefined`.
  854. defined`.
  855.     if (a == null || b == null) return a =// Unwrap any wrapped objects.
  856.  objects.
  857.     if (a instanceof _) a = a._wrapped;
  858.     if (b instanceof _) b = b._wra// Compare `[[Class]]` names.
  859. ]` names.
  860.     var className = toString.call(a);
  861.     if (className !== toString.call(b)) return false;
  862.     switch (className// Strings, numbers, regular expressions, dates, and booleans are compared by value.
  863. by value.
  864.       case '[object RegExp// RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
  865. = '/a/i')
  866.       case '[object String]'// Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
  867.  `"5"` i// equivalent to `new String("5")`.
  868. ng("5")`.
  869.         return '''+ a === '' + b;
  870.       case '[object Number]'// `NaN`s are equivalent, but non-reflexive.
  871. eflexive// Object(NaN) is equivalent to NaN
  872. nt to NaN
  873.         if (+a !== +a) return +b !== +b// An `egal` comparison is performed for other numeric values.
  874. c values.
  875.         return +a === 0 ? 1 / +a === 1 / b : +a === +b;
  876.       case '[object Date]':
  877.       case '[object Boolean]'// Coerce dates and booleans to numeric primitive values. Dates are compared by their
  878.  by thei// millisecond representations. Note that invalid dates with millisecond representations
  879. entation// of `NaN` are not equivalent.
  880. uivalent.
  881.         return +a === +b;
  882.     }
  883.     if (typeof a != 'object' || typeof b != 'object') return f// Assume equality for cyclic structures. The algorithm for detecting cyclic
  884. ng c// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
  885. ion `JO`.
  886.     var length = aStack.length;
  887.     while (length--// Linear search. Performance is inversely proportional to the number of
  888. number// unique nested structures.
  889. ructures.
  890.       if (aStack[length] === a) return bStack[length] === b;
  891. // Objects with different constructors are not equivalent, but `Object`s
  892. `Obj// from different frames are.
  893. ames are.
  894.     var aCtor = a.constructor, bCtor = b.constructor;
  895.     if (
  896.       aCtor !== bCtor// Handle Object.create(x) cases
  897. (x) cases
  898.       'constructor'constructor'nstructor' in b &&
  899.       !(_.isFunction(aCtor) && aCtor instanceof aCtor &&
  900.         _.isFunction(bCtor) && bCtor instanceof bCtor)
  901.     ) {
  902.       return false;
  903. // Add the first object to the stack of traversed objects.
  904.  objects.
  905.     aStack.push(a);
  906.     bStack.push(b);
  907.     var size, re// Recursively compare objects and arrays.
  908. d arrays.
  909.     if (className === '[object Array]'// Compare array lengths to determine if a deep comparison is necessary.
  910. ecessary.
  911.       size = a.length;
  912.       result = size === b.length;
  913.       if (result) // Deep compare the contents, ignoring non-numeric properties.
  914. operties.
  915.         while (size--) {
  916.           if (!(result = eq(a[size], b[size], aStack, bStack))) break;
  917.         }
  918.       }
  919.     } els// Deep compare objects.
  920.  objects.
  921.       var keys = _.keys(a), key;
  922.       size = keys.leng// Ensure that both objects contain the same number of properties before comparing deep equality.
  923. equality.
  924.       result = _.keys(b).length === size;
  925.       if (result) {
  926.         while (size--) {
  927. // Deep compare each member
  928. ch member
  929.           key = keys[size];
  930.           if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
  931.         }
  932.       }
  933. // Remove the first object from the stack of traversed objects.
  934.  objects.
  935.     aStack.pop();
  936.     bStack.pop();
  937.     return result// Perform a deep comparison to check if two objects are equal.
  938. re equal.
  939.   _.isEqual = function(a, b) {
  940.     return eq(a, b, [], [])// Is a given array, string, or object empty?
  941. ct// An "empty" object has no enumerable own-properties.
  942. operties.
  943.   _.isEmpty = function(obj) {
  944.     if (obj == null) return true;
  945.     if (_.isArray(obj) || _.isString(obj) || _.isArguments(obj)) return obj.length === 0;
  946.     for (var key in obj) if (_.has(obj, key)) return false;
  947.     return true// Is a given value a DOM element?
  948.  element?
  949.   _.isElement = function(obj) {
  950.     return !!(obj && obj.nodeType === 1)// Is a given value an array?
  951. an// Delegates to ECMA5's native Array.isArray
  952. y.isArray
  953.   _.isArray = nativeIsArray || function(obj) {
  954.     return toString.call(obj) === '[object Array]'// Is a given variable an object?
  955. n object?
  956.   _.isObject = function(obj) {
  957.     var type = typeof obj;
  958.     return type === 'function' || type === 'object' && !!obj// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
  959. isRegExp.
  960.   _.each([', 'uments', 'Function', 'String', 'Number', 'Date'], function(name) {
  961.    _[' {
  962.     _['is' + name] = function(obj) {
  963.       return toString.call(obj) === '[object ' + name + ']';
  964.     };// Define a fallback version of the method in browsers (ahem, IE), where
  965. E)// there isn't any inspectable "Arguments" type.
  966. ts" type.
  967.   if (!_.isArguments(arguments)) {
  968.     _.isArguments = function(obj) {
  969.       return _.has(obj, 'callee');
  970.     // Optimize `isFunction` if appropriate. Work around an IE 11 bug.
  971. E 11 bug.
  972.   if (typeof unc !== 'function') {
  973.     _.isFunction = function(obj) {
  974.       return typeof obj == 'function' || false;
  975.     // Is a given object a finite number?
  976. e number?
  977.   _.isFinite = function(obj) {
  978.     return isFinite(obj) && !isNaN(parseFloat(obj))// Is the given value `NaN`? (NaN is the only number which does not equal itself).
  979.  itself).
  980.   _.isNaN = function(obj) {
  981.     return _.isNumber(obj) && obj !== +obj// Is a given value a boolean?
  982.  boolean?
  983.   _.isBoolean = function(obj) {
  984.     return obj === true || obj === false || toString.call(obj) === '[object Boolean]'// Is a given value equal to null?
  985.  to null?
  986.   _.isNull = function(obj) {
  987.     return obj === null// Is a given variable undefined?
  988. ndefined?
  989.   _.isUndefined = function(obj) {
  990.     return obj === void 0// Shortcut function for checking if an object has a given property directly
  991.  d// on itself (in other words, not on a prototype).
  992. ototype).
  993.   _.has = function(obj, key) {
  994.     return obj != null && hasOwnProperty.call(obj, key)// Utility Functions
  995. Fu// -----------------
  996. ---// Run Underscore.js in *noConflict* mode, returning the `_` variable to its
  997. le// previous owner. Returns a reference to the Underscore object.
  998. e object.
  999.   _.noConflict = function() {
  1000.     root._ = previousUnderscore;
  1001.     return this// Keep the identity function around for default iteratees.
  1002. teratees.
  1003.   _.identity = function(value) {
  1004.     return value;
  1005.   };
  1006.  
  1007.   _.constant = function(value) {
  1008.     return function() {
  1009.       return value;
  1010.     };
  1011.   };
  1012.  
  1013.   _.noop = function(){};
  1014.  
  1015.   _.property = function(key) {
  1016.     return function(obj) {
  1017.       return obj[key];
  1018.     }// Returns a predicate for checking whether an object has a given set of `key:value` pairs.
  1019. e` pairs.
  1020.   _.matches = function(attrs) {
  1021.     var pairs = _.pairs(attrs), length = pairs.length;
  1022.     return function(obj) {
  1023.       if (obj == null) return !length;
  1024.       obj = new Object(obj);
  1025.       for (var i = 0; i < length; i++) {
  1026.         var pair = pairs[i], key = pair[0];
  1027.         if (pair[1] !== obj[key] || !(key in obj)) return false;
  1028.       }
  1029.       return true;
  1030.     }// Run a function **n** times.
  1031. ** times.
  1032.   _.times = function(n, iteratee, context) {
  1033.     var accum = Array(Math.max(0, n));
  1034.     iteratee = createCallback(iteratee, context, 1);
  1035.     for (var i = 0; i < n; i++) accum[i] = iteratee(i);
  1036.     return accum// Return a random integer between min and max (inclusive).
  1037. clusive).
  1038.   _.random = function(min, max) {
  1039.     if (max == null) {
  1040.       max = min;
  1041.       min = 0;
  1042.     }
  1043.     return min + Math.floor(Math.random() * (max - min + 1))// A (possibly faster) way to get the current timestamp as an integer.
  1044.  integer.
  1045.   _.now = Date.now || function() {
  1046.     return new Date().getTime();// List of HTML entities for escaping.
  1047. escaping.
  1048.   var escapeMap = {
  1049.     '&': '&amp;',
  1050.     ',
  1051.    't;',
  1052.     ',
  1053.    't;',
  1054.     '"',
  1055.    "';',
  1056.     "'": '&#x27;',
  1057.     '`'
  1058.  };
  1059.  var unescapeMap = _.invert(escapeMap);
  1060.  
  1061.  // Functions for escaping and unescaping strings to/from HTML interpolation.
  1062.  var createEscaper = function(map) {
  1063.    var escaper = function(match) {
  1064.      return map[match];
  1065.    };
  1066.    // Regexes for identifying a key that needs to be escaped
  1067.    var source = 'source = '(?:' + _.keys(map).join('|') + ')';
  1068.     var testRegexp = RegExp(source);
  1069.     var replaceRegexp = RegExp(source, 'g');
  1070.     return function(string) {
  1071.       string = string == null ? '' : '' + string;
  1072.       return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
  1073.     };
  1074.   };
  1075.   _.escape = createEscaper(escapeMap);
  1076.   _.unescape = createEscaper(unescap// If the value of the named `property` is a function then invoke it with the
  1077.  w// `object` as context; otherwise, return it.
  1078. eturn it.
  1079.   _.result = function(object, property) {
  1080.     if (object == null) return void 0;
  1081.     var value = object[property];
  1082.     return _.isFunction(value) ? object[property]() : value// Generate a unique integer id (unique within the entire client session).
  1083. se// Useful for temporary DOM ids.
  1084.  DOM ids.
  1085.   var idCounter = 0;
  1086.   _.uniqueId = function(prefix) {
  1087.     var id = ++idCounter + '';
  1088.     return prefix ? prefix + id : id// By default, Underscore uses ERB-style template delimiters, change the
  1089. ha// following template settings to use alternative delimiters.
  1090. limiters.
  1091.   _.templateSettings = {
  1092.     evaluate    : +?)%>/g,
  1093.     inte,
  1094.     interpolate : ]+?)%>/g,
  1095.     esca,
  1096.     escape      : ]+?)%>/g
  1097.   };
  1098.  
  1099.   /
  1100.   };
  1101.  
  1102.   // When customizing `templateSettings`, if you don't want to de// interpolation, evaluation or escaping regex, we need one that is
  1103. e // guaranteed not to match.
  1104. to match.
  1105.   var noMatch = // Ce;
  1106.  
  1107.   // Certain characters need to be escaped so that they can be put// string literal.
  1108.  literal.
  1109.   var escapes = {
  1110.     "'":      "'",
  1111.     '\\':     '\\',
  1112.     'r'':     'r':     '\n':     'n',
  1113.     'u2028'': 'u2028',
  1114.     'u2029'': 'u2029'
  1115.   };
  1116.  
  1117.   var escaper = n|\u2028|\u2029/g;
  1118.  
  1119.   var e;
  1120.  
  1121.   var escapeChar = function(match) {
  1122.     return '\\' + escapes[match]// JavaScript micro-templating, similar to John Resig's implementation.
  1123. en// Underscore templating handles arbitrary delimiters, preserves whitespace,
  1124. it// and correctly escapes quotes within interpolated code.
  1125. te// NB: `oldSettings` only exists for backwards compatibility.
  1126. tibility.
  1127.   _.template = function(text, settings, oldSettings) {
  1128.     if (!settings && oldSettings) settings = oldSettings;
  1129.     settings = _.defaults({}, settings, _.templateSettin// Combine delimiters into one regular expression via alternation.
  1130. ernation.
  1131.     var matcher = RegExp([
  1132.       (settings.escape || noMatch).source,
  1133.       (settings.interpolate || noMatch).source,
  1134.       (settings.evaluate || noMatch).source
  1135.     ].join(', ' + '|$', '// Compile the template source, escaping string literals appropriately.
  1136. priately.
  1137.     var index = 0;
  1138.     var source = "__p+='";
  1139.     text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
  1140.       source += text.slice(index, offset).replace(escaper, escapeChar);
  1141.       index = offset + match.length;
  1142.  
  1143.       if (escape) {
  1144.         source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
  1145.       } else if (interpolate) {
  1146.         source += "'+\n((__t=(" + interpolate + "))==null?'";
  1147.      } else if (evaluate) {
  1148.        source += "'urce += "';\n" + evaluate + "\n__p+='";
  1149.      // Adobe VMs need the match returned to produce the correct offest.
  1150. t offest.
  1151.       return match;
  1152.     });
  1153.     source += "';// If a variable is not specified, place data values in local scope.
  1154. al scope.
  1155.     if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
  1156.  
  1157.     source = "var __t,__p='',__j=Array.prototype.join,"print=function(){__p+=__j.call(arguments,'');};\t",'');};\n" +
  1158.       source + 'return __p;\n';
  1159.  
  1160.     try {
  1161.       var render = new Function(settings.variable || 'obj', '_', source);
  1162.     } catch (e) {
  1163.       e.source = source;
  1164.       throw e;
  1165.     }
  1166.  
  1167.     var template = function(data) {
  1168.       return render.call(this, data, _);
  1169.   // Provide the compiled source as a convenience for precompilation.
  1170. pilation.
  1171.     var argument = settings.variable || 'obj';
  1172.     template.source = ' + argument + 'gument + '){\n' + source + '}';
  1173.  
  1174.     return template// Add a "chain" function. Start chaining a wrapped Underscore object.
  1175. e object.
  1176.   _.chain = function(obj) {
  1177.     var instance = _(obj);
  1178.     instance._chain = true;
  1179.     return instance// OOP
  1180.  
  1181.  // ---------------
  1182. --// If Underscore is called as a function, it returns a wrapped object that
  1183. je// can be used OO-style. This wrapper holds altered versions of all the
  1184. f // underscore functions. Wrapped objects may be chained.
  1185.  ch// Helper function to continue chaining intermediate results.
  1186.  results.
  1187.   var result = function(obj) {
  1188.     return this._chain ? _(obj).chain() : obj// Add your own custom functions to the Underscore object.
  1189. e object.
  1190.   _.mixin = function(obj) {
  1191.     _.each(_.functions(obj), function(name) {
  1192.       var func = _[name] = obj[name];
  1193.       _.prototype[name] = function() {
  1194.         var args = [this._wrapped];
  1195.         push.apply(args, arguments);
  1196.         return result.call(this, func.apply(_, args));
  1197.       };
  1198.     })// Add all of the Underscore functions to the wrapper object.
  1199. r object.
  1200.   _.mix// Add all mutator Array functions to the wrapper.
  1201.  wrapper.
  1202.   _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
  1203.     var method = ArrayProto[name];
  1204.     _.prototype[name] = function() {
  1205.       var obj = this._wrapped;
  1206.       method.apply(obj, arguments);
  1207.       if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
  1208.       return result.call(this, obj);
  1209.     };// Add all accessor Array functions to the wrapper.
  1210.  wrapper.
  1211.   _.each(['join't', 'join', 'slice'], function(name) {
  1212.     var method = ArrayProto[name];
  1213.     _.prototype[name] = function() {
  1214.       return result.call(this, method.apply(this._wrapped, arguments));
  1215.     };// Extracts the result from a wrapped and chained object.
  1216. d object.
  1217.   _.prototype.value = function() {
  1218.     return this._wrapped// AMD registration happens at the end for compatibility with AMD loaders
  1219. D // that may not enforce next-turn semantics on modules. Even though general
  1220. h // practice for AMD registration is to be anonymous, underscore registers
  1221. re// as a named module because, like jQuery, it is a base library that is
  1222. y // popular enough to be bundled in a third party lib, but not be part of
  1223. e // an AMD load request. Those cases could generate an error when an
  1224. r // anonymous define() is called outside of a loader request.
  1225.  request.
  1226.   if (typeof define === 'function' && define.amd) {
  1227.     define('underscore', [], function() {
  1228.       return _;
  1229.     });
  1230.   }
  1231. }.ca

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.