prop_up 0.0.1 → 0.0.2

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