Skip to content

Commit aac4b87

Browse files
committed
Merge branch 'master' of github.com:documentcloud/underscore
2 parents 69e1677 + bf1bddd commit aac4b87

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ test/
22
Rakefile
33
docs/
44
raw/
5+
index.html
6+
underscore-min.js

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@
340340
<a href="http://prototypejs.org/doc/latest/">Prototype.js</a>
341341
(or <a href="http://www.ruby-doc.org/core/classes/Enumerable.html">Ruby</a>),
342342
but without extending any of the built-in JavaScript objects. It's the
343-
tie to go along with <a href="http://docs.jquery.com">jQuery</a>'s tux,
343+
tie to go along with <a href="http://jquery.com">jQuery</a>'s tux,
344344
and <a href="http://backbonejs.org">Backbone.js</a>'s suspenders.
345345
</p>
346346

@@ -1043,7 +1043,7 @@ <h2 id="functions">Function (uh, ahem) Functions</h2>
10431043
<p id="debounce">
10441044
<b class="header">debounce</b><code>_.debounce(function, wait, [immediate])</code>
10451045
<br />
1046-
Creates and returns a new debounced version of the passed function that
1046+
Creates and returns a new debounced version of the passed function which
10471047
will postpone its execution until after
10481048
<b>wait</b> milliseconds have elapsed since the last time it
10491049
was invoked. Useful for implementing behavior that should only happen
@@ -1486,7 +1486,8 @@ <h2 id="utility">Utility Functions</h2>
14861486
<b class="header">times</b><code>_.times(n, iterator, [context])</code>
14871487
<br />
14881488
Invokes the given iterator function <b>n</b> times. Each invocation of
1489-
<b>iterator</b> is called with an <tt>index</tt> argument.
1489+
<b>iterator</b> is called with an <tt>index</tt> argument. Produces an
1490+
array of the returned values.
14901491
<br />
14911492
<i>Note: this example uses the <a href="#chaining">chaining syntax</a></i>.
14921493
</p>

test/functions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ $(document).ready(function() {
241241
equal(num, 1);
242242
});
243243

244+
test("Recursive onced function.", 1, function() {
245+
var f = _.once(function(){
246+
ok(true);
247+
f();
248+
});
249+
f();
250+
});
251+
244252
test("wrap", function() {
245253
var greet = function(name){ return "hi: " + name; };
246254
var backwards = _.wrap(greet, function(func, name){ return func(name) + ' ' + name.split('').reverse().join(''); });

underscore.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Underscore.js 1.4.4
22
// http://underscorejs.org
3-
// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
3+
// (c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
4+
// (c) 2011-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
45
// Underscore may be freely distributed under the MIT license.
56

67
(function() {
@@ -21,11 +22,12 @@
2122
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
2223

2324
// Create quick reference variables for speed access to core prototypes.
24-
var push = ArrayProto.push,
25-
slice = ArrayProto.slice,
26-
concat = ArrayProto.concat,
27-
toString = ObjProto.toString,
28-
hasOwnProperty = ObjProto.hasOwnProperty;
25+
var
26+
push = ArrayProto.push,
27+
slice = ArrayProto.slice,
28+
concat = ArrayProto.concat,
29+
toString = ObjProto.toString,
30+
hasOwnProperty = ObjProto.hasOwnProperty;
2931

3032
// All **ECMAScript 5** native function implementations that we hope to use
3133
// are declared here. We don't use native implementations of the array extras
@@ -235,7 +237,7 @@
235237

236238
// Return the maximum element or (element-based computation).
237239
// Can't optimize arrays of integers longer than 65,535 elements.
238-
// See: https://bugs.webkit.org/show_bug.cgi?id=80797
240+
// See [WebKit Bug 80797](https://bugs.webkit.org/show_bug.cgi?id=80797)
239241
_.max = function(obj, iterator, context) {
240242
if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
241243
return Math.max.apply(Math, obj);
@@ -486,16 +488,8 @@
486488
// `[['a',1],['b',2],['c',3]]` returns the array
487489
// [['a','b','c'],[1,2,3]].
488490
_.unzip = function(tuples) {
489-
var results = [];
490-
_.each(tuples, function (tuple, tupleIndex) {
491-
_.each(tuple, function (value, itemIndex) {
492-
if (results.length <= itemIndex) {
493-
results[itemIndex] = [];
494-
}
495-
results[itemIndex][tupleIndex] = value;
496-
});
497-
});
498-
return results;
491+
var maxLen = _.max(_.pluck(tuples, "length"))
492+
return _.times(maxLen, _.partial(_.pluck, tuples));
499493
};
500494

501495
// Converts lists into objects. Pass either a single array of `[key, value]`
@@ -835,7 +829,7 @@
835829
// Internal recursive comparison function for `isEqual`.
836830
var eq = function(a, b, aStack, bStack) {
837831
// Identical objects are equal. `0 === -0`, but they aren't identical.
838-
// See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
832+
// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
839833
if (a === b) return a !== 0 || 1 / a == 1 / b;
840834
// A strict comparison is necessary because `null == undefined`.
841835
if (a == null || b == null) return a === b;

0 commit comments

Comments
 (0)