|
3 | 3 | <title>callbacks.add()</title>
|
4 | 4 | <signature>
|
5 | 5 | <added>1.7</added>
|
6 |
| - <argument name="callbacks" type="Function"> |
| 6 | + <argument name="callbacks" type="Function, Array"> |
7 | 7 | <desc>A function, or array of functions, that are to be added to the callback list.</desc>
|
8 | 8 | </argument>
|
9 | 9 | </signature>
|
10 | 10 | <desc>Add a callback or a collection of callbacks to a callback list.</desc>
|
11 | 11 | <longdesc>
|
12 | 12 | <p>This method returns the Callbacks object onto which it is attached (<code>this</code>). </p>
|
13 | 13 | <h2 id="example-1">Example</h2>
|
14 |
| - <p>Using <code>callbacks.add()</code> to add new callbacks to a callback list:</p> |
15 |
| - <pre><code> |
16 |
| -// a sample logging function to be added to a callbacks list |
17 |
| -var foo = function( value ){ |
18 |
| - console.log( 'foo:' + value ); |
19 |
| -} |
| 14 | + <p>Use <code>callbacks.add()</code> to add new callbacks to a callback list:</p> |
| 15 | + <pre><code><![CDATA[// a sample logging function to be added to a callbacks list |
| 16 | +var foo = function( value ) { |
| 17 | + console.log( "foo: " + value ); |
| 18 | +}; |
20 | 19 |
|
21 | 20 | // another function to also be added to the list
|
22 | 21 | var bar = function( value ){
|
23 |
| - console.log( 'bar:' + value ); |
24 |
| -} |
| 22 | + console.log( "bar: " + value ); |
| 23 | +}; |
25 | 24 |
|
26 | 25 | var callbacks = $.Callbacks();
|
27 | 26 |
|
28 |
| -// add the function 'foo' to the list |
| 27 | +// add the function "foo" to the list |
29 | 28 | callbacks.add( foo );
|
30 | 29 |
|
31 | 30 | // fire the items on the list
|
32 |
| -callbacks.fire( 'hello' ); |
33 |
| -// outputs: 'foo: hello' |
| 31 | +callbacks.fire( "hello" ); |
| 32 | +// outputs: "foo: hello" |
34 | 33 |
|
35 |
| -// add the function 'bar' to the list |
| 34 | +// add the function "bar" to the list |
36 | 35 | callbacks.add( bar );
|
37 | 36 |
|
38 | 37 | // fire the items on the list again
|
39 |
| -callbacks.fire( 'world' ); |
| 38 | +callbacks.fire( "world" ); |
40 | 39 |
|
41 | 40 | // outputs:
|
42 |
| -// 'foo: world' |
43 |
| -// 'bar: world' |
44 |
| -</code> |
| 41 | +// "foo: world" |
| 42 | +// "bar: world" |
| 43 | +]]></code> |
45 | 44 | </pre>
|
46 | 45 | </longdesc>
|
47 | 46 | <category slug="callbacks-object"/>
|
|
0 commit comments