underscore-source 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Underscore
2
2
  module Source
3
- VERSION = "1.2.2"
3
+ VERSION = "1.2.3"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
- // Underscore.js 1.2.2
2
- // (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.
1
+ // Underscore.js 1.2.3
2
+ // (c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
3
3
  // Underscore is freely distributable under the MIT license.
4
4
  // Portions of Underscore are inspired or borrowed from Prototype,
5
5
  // Oliver Steele's Functional, and John Resig's Micro-Templating.
@@ -25,6 +25,7 @@
25
25
 
26
26
  // Create quick reference variables for speed access to core prototypes.
27
27
  var slice = ArrayProto.slice,
28
+ concat = ArrayProto.concat,
28
29
  unshift = ArrayProto.unshift,
29
30
  toString = ObjProto.toString,
30
31
  hasOwnProperty = ObjProto.hasOwnProperty;
@@ -67,7 +68,7 @@
67
68
  }
68
69
 
69
70
  // Current version.
70
- _.VERSION = '1.2.2';
71
+ _.VERSION = '1.2.3';
71
72
 
72
73
  // Collection Functions
73
74
  // --------------------
@@ -107,7 +108,7 @@
107
108
  // **Reduce** builds up a single result from a list of values, aka `inject`,
108
109
  // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
109
110
  _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
110
- var initial = memo !== void 0;
111
+ var initial = arguments.length > 2;
111
112
  if (obj == null) obj = [];
112
113
  if (nativeReduce && obj.reduce === nativeReduce) {
113
114
  if (context) iterator = _.bind(iterator, context);
@@ -121,20 +122,22 @@
121
122
  memo = iterator.call(context, memo, value, index, list);
122
123
  }
123
124
  });
124
- if (!initial) throw new TypeError("Reduce of empty array with no initial value");
125
+ if (!initial) throw new TypeError('Reduce of empty array with no initial value');
125
126
  return memo;
126
127
  };
127
128
 
128
129
  // The right-associative version of reduce, also known as `foldr`.
129
130
  // Delegates to **ECMAScript 5**'s native `reduceRight` if available.
130
131
  _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
132
+ var initial = arguments.length > 2;
131
133
  if (obj == null) obj = [];
132
134
  if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
133
135
  if (context) iterator = _.bind(iterator, context);
134
- return memo !== void 0 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
136
+ return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
135
137
  }
136
- var reversed = (_.isArray(obj) ? obj.slice() : _.toArray(obj)).reverse();
137
- return _.reduce(reversed, iterator, memo, context);
138
+ var reversed = _.toArray(obj).reverse();
139
+ if (context && !initial) iterator = _.bind(iterator, context);
140
+ return initial ? _.reduce(reversed, iterator, memo, context) : _.reduce(reversed, iterator);
138
141
  };
139
142
 
140
143
  // Return the first value which passes a truth test. Aliased as `detect`.
@@ -189,7 +192,7 @@
189
192
  // Delegates to **ECMAScript 5**'s native `some` if available.
190
193
  // Aliased as `any`.
191
194
  var any = _.some = _.any = function(obj, iterator, context) {
192
- iterator = iterator || _.identity;
195
+ iterator || (iterator = _.identity);
193
196
  var result = false;
194
197
  if (obj == null) return result;
195
198
  if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
@@ -402,10 +405,11 @@
402
405
  });
403
406
  };
404
407
 
405
- // Take the difference between one array and another.
408
+ // Take the difference between one array and a number of other arrays.
406
409
  // Only the elements present in just the first array will remain.
407
- _.difference = function(array, other) {
408
- return _.filter(array, function(value){ return !_.include(other, value); });
410
+ _.difference = function(array) {
411
+ var rest = _.flatten(slice.call(arguments, 1));
412
+ return _.filter(array, function(value){ return !_.include(rest, value); });
409
413
  };
410
414
 
411
415
  // Zip together multiple lists into a single array -- elements that share
@@ -432,7 +436,7 @@
432
436
  return array[i] === item ? i : -1;
433
437
  }
434
438
  if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item);
435
- for (i = 0, l = array.length; i < l; i++) if (array[i] === item) return i;
439
+ for (i = 0, l = array.length; i < l; i++) if (i in array && array[i] === item) return i;
436
440
  return -1;
437
441
  };
438
442
 
@@ -441,7 +445,7 @@
441
445
  if (array == null) return -1;
442
446
  if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item);
443
447
  var i = array.length;
444
- while (i--) if (array[i] === item) return i;
448
+ while (i--) if (i in array && array[i] === item) return i;
445
449
  return -1;
446
450
  };
447
451
 
@@ -579,7 +583,7 @@
579
583
  // conditionally execute the original function.
580
584
  _.wrap = function(func, wrapper) {
581
585
  return function() {
582
- var args = [func].concat(slice.call(arguments));
586
+ var args = concat.apply([func], arguments);
583
587
  return wrapper.apply(this, args);
584
588
  };
585
589
  };
@@ -587,9 +591,9 @@
587
591
  // Returns a function that is the composition of a list of functions, each
588
592
  // consuming the return value of the function that follows.
589
593
  _.compose = function() {
590
- var funcs = slice.call(arguments);
594
+ var funcs = arguments;
591
595
  return function() {
592
- var args = slice.call(arguments);
596
+ var args = arguments;
593
597
  for (var i = funcs.length - 1; i >= 0; i--) {
594
598
  args = [funcs[i].apply(this, args)];
595
599
  }
@@ -677,8 +681,8 @@
677
681
  if (a._chain) a = a._wrapped;
678
682
  if (b._chain) b = b._wrapped;
679
683
  // Invoke a custom `isEqual` method if one is provided.
680
- if (_.isFunction(a.isEqual)) return a.isEqual(b);
681
- if (_.isFunction(b.isEqual)) return b.isEqual(a);
684
+ if (a.isEqual && _.isFunction(a.isEqual)) return a.isEqual(b);
685
+ if (b.isEqual && _.isFunction(b.isEqual)) return b.isEqual(a);
682
686
  // Compare `[[Class]]` names.
683
687
  var className = toString.call(a);
684
688
  if (className != toString.call(b)) return false;
@@ -687,13 +691,11 @@
687
691
  case '[object String]':
688
692
  // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
689
693
  // equivalent to `new String("5")`.
690
- return String(a) == String(b);
694
+ return a == String(b);
691
695
  case '[object Number]':
692
- a = +a;
693
- b = +b;
694
696
  // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
695
697
  // other numeric values.
696
- return a != a ? b != b : (a == 0 ? 1 / a == 1 / b : a == b);
698
+ return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
697
699
  case '[object Date]':
698
700
  case '[object Boolean]':
699
701
  // Coerce dates and booleans to numeric primitive values. Dates are compared by their
@@ -733,7 +735,7 @@
733
735
  }
734
736
  } else {
735
737
  // Objects with different constructors are not equivalent.
736
- if ("constructor" in a != "constructor" in b || a.constructor != b.constructor) return false;
738
+ if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false;
737
739
  // Deep compare objects.
738
740
  for (var key in a) {
739
741
  if (hasOwnProperty.call(a, key)) {
@@ -786,11 +788,10 @@
786
788
  };
787
789
 
788
790
  // Is a given variable an arguments object?
789
- if (toString.call(arguments) == '[object Arguments]') {
790
- _.isArguments = function(obj) {
791
- return toString.call(obj) == '[object Arguments]';
792
- };
793
- } else {
791
+ _.isArguments = function(obj) {
792
+ return toString.call(obj) == '[object Arguments]';
793
+ };
794
+ if (!_.isArguments(arguments)) {
794
795
  _.isArguments = function(obj) {
795
796
  return !!(obj && hasOwnProperty.call(obj, 'callee'));
796
797
  };
@@ -915,7 +916,10 @@
915
916
  .replace(/\t/g, '\\t')
916
917
  + "');}return __p.join('');";
917
918
  var func = new Function('obj', '_', tmpl);
918
- return data ? func(data, _) : function(data) { return func(data, _) };
919
+ if (data) return func(data, _);
920
+ return function(data) {
921
+ return func.call(this, data, _);
922
+ };
919
923
  };
920
924
 
921
925
  // The OOP Wrapper
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: underscore-source
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.2
5
+ version: 1.2.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel X. Moore