underscore-source 1.1.5 → 1.1.6

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.1.5"
3
+ VERSION = "1.1.6"
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- // Underscore.js 1.1.5
1
+ // Underscore.js 1.1.6
2
2
  // (c) 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,
@@ -59,7 +59,7 @@
59
59
  }
60
60
 
61
61
  // Current version.
62
- _.VERSION = '1.1.5';
62
+ _.VERSION = '1.1.6';
63
63
 
64
64
  // Collection Functions
65
65
  // --------------------
@@ -168,7 +168,6 @@
168
168
  // Delegates to **ECMAScript 5**'s native `every` if available.
169
169
  // Aliased as `all`.
170
170
  _.every = _.all = function(obj, iterator, context) {
171
- iterator = iterator || _.identity;
172
171
  var result = true;
173
172
  if (obj == null) return result;
174
173
  if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
@@ -182,7 +181,7 @@
182
181
  // Delegates to **ECMAScript 5**'s native `some` if available.
183
182
  // Aliased as `any`.
184
183
  var any = _.some = _.any = function(obj, iterator, context) {
185
- iterator = iterator || _.identity;
184
+ iterator || (iterator = _.identity);
186
185
  var result = false;
187
186
  if (obj == null) return result;
188
187
  if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
@@ -208,7 +207,7 @@
208
207
  _.invoke = function(obj, method) {
209
208
  var args = slice.call(arguments, 2);
210
209
  return _.map(obj, function(value) {
211
- return (method ? value[method] : value).apply(value, args);
210
+ return (method.call ? method || value : value[method]).apply(value, args);
212
211
  });
213
212
  };
214
213
 
@@ -255,7 +254,7 @@
255
254
  // Use a comparator function to figure out at what index an object should
256
255
  // be inserted so as to maintain order. Uses binary search.
257
256
  _.sortedIndex = function(array, obj, iterator) {
258
- iterator = iterator || _.identity;
257
+ iterator || (iterator = _.identity);
259
258
  var low = 0, high = array.length;
260
259
  while (low < high) {
261
260
  var mid = (low + high) >> 1;
@@ -408,8 +407,9 @@
408
407
  // Create a function bound to a given object (assigning `this`, and arguments,
409
408
  // optionally). Binding with arguments is also known as `curry`.
410
409
  // Delegates to **ECMAScript 5**'s native `Function.bind` if available.
410
+ // We check for `func.bind` first, to fail fast when `func` is undefined.
411
411
  _.bind = function(func, obj) {
412
- if (nativeBind && func.bind === nativeBind) return func.bind.apply(func, slice.call(arguments, 1));
412
+ if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
413
413
  var args = slice.call(arguments, 2);
414
414
  return function() {
415
415
  return func.apply(obj, args.concat(slice.call(arguments)));
@@ -428,7 +428,7 @@
428
428
  // Memoize an expensive function by storing its results.
429
429
  _.memoize = function(func, hasher) {
430
430
  var memo = {};
431
- hasher = hasher || _.identity;
431
+ hasher || (hasher = _.identity);
432
432
  return function() {
433
433
  var key = hasher.apply(this, arguments);
434
434
  return hasOwnProperty.call(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
@@ -509,6 +509,14 @@
509
509
  };
510
510
  };
511
511
 
512
+ // Returns a function that will only be executed after being called N times.
513
+ _.after = function(times, func) {
514
+ return function() {
515
+ if (--times < 1) { return func.apply(this, arguments); }
516
+ };
517
+ };
518
+
519
+
512
520
  // Object Functions
513
521
  // ----------------
514
522
 
@@ -535,7 +543,9 @@
535
543
  // Extend a given object with all the properties in passed-in object(s).
536
544
  _.extend = function(obj) {
537
545
  each(slice.call(arguments, 1), function(source) {
538
- for (var prop in source) obj[prop] = source[prop];
546
+ for (var prop in source) {
547
+ if (source[prop] !== void 0) obj[prop] = source[prop];
548
+ }
539
549
  });
540
550
  return obj;
541
551
  };
@@ -543,7 +553,9 @@
543
553
  // Fill in a given object with default properties.
544
554
  _.defaults = function(obj) {
545
555
  each(slice.call(arguments, 1), function(source) {
546
- for (var prop in source) if (obj[prop] == null) obj[prop] = source[prop];
556
+ for (var prop in source) {
557
+ if (obj[prop] == null) obj[prop] = source[prop];
558
+ }
547
559
  });
548
560
  return obj;
549
561
  };
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: underscore-source
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.5
5
+ version: 1.1.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel X. Moore