underscore-source 0.3.1 → 0.3.2

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 = "0.3.1"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  end
@@ -10,23 +10,20 @@
10
10
 
11
11
  /*------------------------- Baseline setup ---------------------------------*/
12
12
 
13
- // Are we running in CommonJS or in the browser?
14
- var commonJS = (typeof window === 'undefined' && typeof exports !== 'undefined');
13
+ // Establish the root object, "window" in the browser, or "global" on the server.
14
+ var root = this;
15
15
 
16
16
  // Save the previous value of the "_" variable.
17
- var previousUnderscore = commonJS ? null : window._;
18
-
19
- // Keep the identity function around for default iterators.
20
- var identity = function(value) { return value; };
17
+ var previousUnderscore = root._;
21
18
 
22
19
  // Create a safe reference to the Underscore object for the functions below.
23
- var _ = {};
20
+ var _ = root._ = {};
24
21
 
25
- // Export the Underscore object for CommonJS, assign it globally otherwise.
26
- commonJS ? _ = exports : window._ = _;
22
+ // Export the Underscore object for CommonJS.
23
+ if (typeof exports !== 'undefined') _ = exports;
27
24
 
28
25
  // Current version.
29
- _.VERSION = '0.3.1';
26
+ _.VERSION = '0.3.2';
30
27
 
31
28
  /*------------------------ Collection Functions: ---------------------------*/
32
29
 
@@ -107,7 +104,7 @@
107
104
  // Determine whether all of the elements match a truth test. Delegate to
108
105
  // JavaScript 1.6's every(), if it is present.
109
106
  _.all = function(obj, iterator, context) {
110
- iterator = iterator || identity;
107
+ iterator = iterator || _.identity;
111
108
  if (obj.every) return obj.every(iterator, context);
112
109
  var result = true;
113
110
  _.each(obj, function(value, index, list) {
@@ -119,7 +116,7 @@
119
116
  // Determine if at least one element in the object matches a truth test. Use
120
117
  // JavaScript 1.6's some(), if it exists.
121
118
  _.any = function(obj, iterator, context) {
122
- iterator = iterator || identity;
119
+ iterator = iterator || _.identity;
123
120
  if (obj.some) return obj.some(iterator, context);
124
121
  var result = false;
125
122
  _.each(obj, function(value, index, list) {
@@ -192,7 +189,7 @@
192
189
  // Use a comparator function to figure out at what index an object should
193
190
  // be inserted so as to maintain order. Uses binary search.
194
191
  _.sortedIndex = function(array, obj, iterator) {
195
- iterator = iterator || identity;
192
+ iterator = iterator || _.identity;
196
193
  var low = 0, high = array.length;
197
194
  while (low < high) {
198
195
  var mid = (low + high) >> 1;
@@ -360,7 +357,7 @@
360
357
 
361
358
  // Retrieve the values of an object's properties.
362
359
  _.values = function(obj) {
363
- return _.map(obj, identity);
360
+ return _.map(obj, _.identity);
364
361
  };
365
362
 
366
363
  // Extend a given object with all of the properties in a source object.
@@ -421,10 +418,15 @@
421
418
  // Run Underscore.js in noConflict mode, returning the '_' variable to its
422
419
  // previous owner. Returns a reference to the Underscore object.
423
420
  _.noConflict = function() {
424
- if (!commonJS) window._ = previousUnderscore;
421
+ root._ = previousUnderscore;
425
422
  return this;
426
423
  };
427
424
 
425
+ // Keep the identity function around for default iterators.
426
+ _.identity = function(value) {
427
+ return value;
428
+ };
429
+
428
430
  // Generate a unique integer id (unique within the entire client session).
429
431
  // Useful for temporary DOM ids.
430
432
  _.uniqueId = function(prefix) {
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: underscore-source
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.1
5
+ version: 0.3.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel X. Moore