Skip to content

Commit

Permalink
add _.noop
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers committed Mar 1, 2014
1 parent 27cda68 commit fa90c00
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,13 @@ <h2 id="utility">Utility Functions</h2>
moe === _.constant(moe)();
=&gt; true</pre>

<p id="noop">
<b class="header">noop</b><code>_.noop()</code>
<br />
Returns <tt>undefined</tt> irrespective of the arguments passed to it.
Useful as the default for optional callback arguments.
</p>

<p id="times">
<b class="header">times</b><code>_.times(n, iterator, [context])</code>
<br />
Expand Down
4 changes: 4 additions & 0 deletions test/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
equal(_.constant(moe)(), moe, 'should create a function that returns moe');
});

test('noop', function() {
strictEqual(_.noop('curly', 'larry', 'moe'), undefined, 'should always return undefined');
});

test('property', function() {
var moe = {name : 'moe'};
equal(_.property('name')(moe), 'moe', 'should return the property with the given name');
Expand Down
2 changes: 2 additions & 0 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,8 @@
};
};

_.noop = function() {};

_.property = function(key) {
return function(obj) {
return obj[key];
Expand Down

0 comments on commit fa90c00

Please sign in to comment.