Skip to content

Commit

Permalink
Underscore 0.5.8, with collection functions that once again work on N…
Browse files Browse the repository at this point in the history
…odeLists and HTMLCollections
  • Loading branch information
jashkenas committed Jan 28, 2010
1 parent 21f37e4 commit 5b5ee87
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
15 changes: 12 additions & 3 deletions index.html
Expand Up @@ -111,11 +111,11 @@ <h2>Downloads <i style="padding-left: 12px; font-size:12px;">(Right-click, and u
<p>
<table>
<tr>
<td><a href="underscore.js">Development Version (0.5.7)</a></td>
<td><a href="underscore.js">Development Version (0.5.8)</a></td>
<td><i>22kb, Uncompressed with Comments</i></td>
</tr>
<tr>
<td><a href="underscore-min.js">Production Version (0.5.7)</a></td>
<td><a href="underscore-min.js">Production Version (0.5.8)</a></td>
<td><i>3kb, Packed and Gzipped</i></td>
</tr>
</table>
Expand Down Expand Up @@ -1097,10 +1097,19 @@ <h2>Links &amp; Suggested Reading</h2>

<h2>Change Log</h2>

<p>
<b class="header">0.5.8</b><br />
Fixed Underscore's collection functions to work on
<a href="https://developer.mozilla.org/En/DOM/NodeList">NodeLists</a> and
<a href="https://developer.mozilla.org/En/DOM/HTMLCollection">HTMLCollections</a>
once more, thanks to
<a href="http://github.com/jmtulloss">Justin Tulloss</a>.
</p>

<p>
<b class="header">0.5.7</b><br />
A safer implementation of <tt>_.isArguments</tt>, and a
faster <tt>_.isNumber</tt>, thanks to
faster <tt>_.isNumber</tt>,<br />thanks to
<a href="http://jedschmidt.com/">Jed Schmidt</a>.
</p>

Expand Down
6 changes: 6 additions & 0 deletions test/collections.js
Expand Up @@ -44,6 +44,12 @@ $(document).ready(function() {

var doubled = _([1, 2, 3]).map(function(num){ return num * 2; });
equals(doubled.join(', '), '2, 4, 6', 'OO-style doubled numbers');

var ids = _.map(document.body.childNodes, function(n){ return n.id; });
ok(_.include(ids, 'qunit-header'), 'can use collection methods on NodeLists');

var ids = _.map(document.images, function(n){ return n.id; });
ok(ids[0] == 'chart_image', 'can use collection methods on HTMLCollections');
});

test('collections: reduce', function() {
Expand Down
10 changes: 5 additions & 5 deletions underscore-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions underscore.js
Expand Up @@ -38,7 +38,7 @@
propertyIsEnumerable = Object.prototype.propertyIsEnumerable;

// Current version.
_.VERSION = '0.5.7';
_.VERSION = '0.5.8';

// ------------------------ Collection Functions: ---------------------------

Expand All @@ -49,7 +49,7 @@
try {
if (obj.forEach) {
obj.forEach(iterator, context);
} else if (_.isArray(obj) || _.isArguments(obj)) {
} else if (_.isNumber(obj.length)) {
for (var i=0, l=obj.length; i<l; i++) iterator.call(context, obj[i], i, obj);
} else {
var keys = _.keys(obj), l = keys.length;
Expand Down Expand Up @@ -152,7 +152,7 @@
// Determine if a given value is included in the array or object,
// based on '==='.
_.include = function(obj, target) {
if (_.isArray(obj)) return _.indexOf(obj, target) != -1;
if (obj && _.isFunction(obj.indexOf)) return _.indexOf(obj, target) != -1;
var found = false;
_.each(obj, function(value) {
if (found = value === target) _.breakLoop();
Expand Down Expand Up @@ -400,7 +400,7 @@

// Retrieve the names of an object's properties.
_.keys = function(obj) {
if(_.isArray(obj)) return _.range(0, obj.length);
if (_.isArray(obj)) return _.range(0, obj.length);
var keys = [];
for (var key in obj) if (hasOwnProperty.call(obj, key)) keys.push(key);
return keys;
Expand Down

0 comments on commit 5b5ee87

Please sign in to comment.