Skip to content

Commit

Permalink
Documenting _.once
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Mar 21, 2011
1 parent 3911906 commit 065dcbb
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ <h2>Table of Contents</h2>
<span class="methods"><a href="#bind">bind</a>, <a href="#bindAll">bindAll</a>,
<a href="#memoize">memoize</a>, <a href="#delay">delay</a>, <a href="#defer">defer</a>,
<a href="#throttle">throttle</a>, <a href="#debounce">debounce</a>,
<a href="#wrap">wrap</a>, <a href="#compose">compose</a></span>
<a href="#once">once</a>, <a href="#wrap">wrap</a>, <a href="#compose">compose</a></span>
</p>

<p>
Expand Down Expand Up @@ -738,6 +738,21 @@ <h2>Function (uh, ahem) Functions</h2>
<pre>
var lazyLayout = _.debounce(calculateLayout, 300);
$(window).resize(lazyLayout);
</pre>

<p id="once">
<b class="header">once</b><code>_.once(function)</code>
<br />
Creates a version of the function that can only be called one time.
Repeated calls to the modified function will have no effect, returning
the value from the original call. Useful for initialization functions,
instead of having to set a boolean flag and then check it later.
</p>
<pre>
var initialize = _.once(createApplication);
initialize();
initialize();
// Application is only created once.
</pre>

<p id="wrap">
Expand Down

0 comments on commit 065dcbb

Please sign in to comment.