defacer 0.0.1 → 0.1.0

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