commit extjs-2.2.1
[extjs.git] / docs / output / Function.html
1         <div class="body-wrap">
2         <div class="top-tools">
3             <a class="inner-link" href="#Function-props"><img src="../resources/images/default/s.gif" class="item-icon icon-prop">Properties</a>
4             <a class="inner-link" href="#Function-methods"><img src="../resources/images/default/s.gif" class="item-icon icon-method">Methods</a>
5             <a class="inner-link" href="#Function-events"><img src="../resources/images/default/s.gif" class="item-icon icon-event">Events</a>
6                         <a class="bookmark" href="../docs/?class=Function"><img src="../resources/images/default/s.gif" class="item-icon icon-fav">Direct Link</a>
7         </div>
8                 <h1>Class Function</h1>
9         <table cellspacing="0">
10             <tr><td class="label">Package:</td><td class="hd-info">Global</td></tr>
11             <tr><td class="label">Defined In:</td><td class="hd-info"><a href="../src/Ext.js" target="_blank">Ext.js</a></td></tr>
12             <tr><td class="label">Class:</td><td class="hd-info">Function</td></tr>
13                                     <tr><td class="label">Extends:</td><td class="hd-info">Object</td></tr>
14                     </table>
15         <div class="description">
16             These functions are available on every Function object (any JavaScript function).        </div>
17         
18         <div class="hr"></div>
19                 <a id="Function-props"></a>
20         <h2>Public Properties</h2>
21         <div class="no-members">This class has no public properties.</div>        <a id="Function-methods"></a>
22         <h2>Public Methods</h2>
23                 <table cellspacing="0" class="member-table">
24             <tr>
25                 <th class="sig-header" colspan="2">Method</th>
26                 <th class="msource-header">Defined By</th>
27             </tr>
28                 <tr class="method-row expandable">\r
29         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
30         <td class="sig">\r
31         <a id="Function-createCallback"></a>\r
32             <b>createCallback</b>() : Function            <div class="mdesc">\r
33                         <div class="short">Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
34 Call directly on any function. Example: ...</div>\r
35             <div class="long">\r
36                 Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
37 Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
38 Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
39 callback, use <a ext:cls="Function" ext:member="createDelegate" href="output/Function.html#createDelegate">createDelegate</a> instead.</b> The function returned by createCallback always
40 executes in the window scope.
41 <p>This method is required when you want to pass arguments to a callback function.  If no arguments
42 are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
43 However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
44 would simply execute immediately when the code is parsed. Example usage:
45 <pre><code>var sayHi = <b>function</b>(name){
46     alert(<em>'Hi, '</em> + name);
47 }
48
49 <i>// clicking the button alerts <em>"Hi, Fred"</em></i>
50 <b>new</b> Ext.Button({
51     text: <em>'Say Hi'</em>,
52     renderTo: Ext.getBody(),
53     handler: sayHi.createCallback(<em>'Fred'</em>)
54 });</code></pre>    <div class="mdetail-params">\r
55         <strong>Parameters:</strong>\r
56         <ul><li>None.</li>        </ul>\r
57         <strong>Returns:</strong>\r
58         <ul>\r
59             <li><code>Function</code><div class="sub-desc">The new function</div></li>\r
60         </ul>\r
61     </div>\r
62                 </div>\r
63                         </div>\r
64         </td>\r
65         <td class="msource">Function</td>\r
66     </tr>\r
67         <tr class="method-row alt expandable">\r
68         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
69         <td class="sig">\r
70         <a id="Function-createDelegate"></a>\r
71             <b>createDelegate</b>(&nbsp;<span class="optional" title="Optional">[<code>Object obj</code>]</span>, <span class="optional" title="Optional">[<code>Array args</code>]</span>, <span class="optional" title="Optional">[<code>Boolean/Number appendArgs</code>]</span>&nbsp;) : Function            <div class="mdesc">\r
72                         <div class="short">Creates a delegate (callback) that sets the scope to obj.
73 Call directly on any function. Example: this.myFunction.cre...</div>\r
74             <div class="long">\r
75                 Creates a delegate (callback) that sets the scope to obj.
76 Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
77 Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
78 callback points to obj. Example usage:
79 <pre><code>var sayHi = <b>function</b>(name){
80     <i>// Note <b>this</b> use of <em>"<b>this</b>.text"</em> here.  This <b>function</b> expects to</i>
81     <i>// execute within a scope that contains a text property.  In <b>this</b></i>
82     <i>// example, the <em>"<b>this</b>"</em> variable is pointing to the btn object that</i>
83     <i>// was passed <b>in</b> createDelegate below.</i>
84     alert(<em>'Hi, '</em> + name + <em>'. You clicked the "'</em> + <b>this</b>.text + <em>'" button.'</em>);
85 }
86
87 <b>var</b> btn = <b>new</b> Ext.Button({
88     text: <em>'Say Hi'</em>,
89     renderTo: Ext.getBody()
90 });
91
92 <i>// This callback will execute <b>in</b> the scope of the</i>
93 <i>// button instance. Clicking the button alerts</i>
94 <i>// <em>"Hi, Fred. You clicked the "</em>Say Hi<em>" button."</em></i>
95 btn.on(<em>'click'</em>, sayHi.createDelegate(btn, [<em>'Fred'</em>]));</code></pre>    <div class="mdetail-params">\r
96         <strong>Parameters:</strong>\r
97         <ul><li><code>obj</code> : Object<div class="sub-desc">(optional) The object for which the scope is set</div></li><li><code>args</code> : Array<div class="sub-desc">(optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)</div></li><li><code>appendArgs</code> : Boolean/Number<div class="sub-desc">(optional) if True args are appended to call args instead of overriding,
98 if a number the args are inserted at the specified position</div></li>        </ul>\r
99         <strong>Returns:</strong>\r
100         <ul>\r
101             <li><code>Function</code><div class="sub-desc">The new function</div></li>\r
102         </ul>\r
103     </div>\r
104                 </div>\r
105                         </div>\r
106         </td>\r
107         <td class="msource">Function</td>\r
108     </tr>\r
109         <tr class="method-row expandable">\r
110         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
111         <td class="sig">\r
112         <a id="Function-createInterceptor"></a>\r
113             <b>createInterceptor</b>(&nbsp;<code>Function fcn</code>, <span class="optional" title="Optional">[<code>Object scope</code>]</span>&nbsp;) : Function            <div class="mdesc">\r
114                         <div class="short">Creates an interceptor function. The passed fcn is called before the original one. If it returns false,
115 the original ...</div>\r
116             <div class="long">\r
117                 Creates an interceptor function. The passed fcn is called before the original one. If it returns false,
118 the original one is not called. The resulting function returns the results of the original function.
119 The passed fcn is called with the parameters of the original function. Example usage:
120 <pre><code>var sayHi = <b>function</b>(name){
121     alert(<em>'Hi, '</em> + name);
122 }
123
124 sayHi(<em>'Fred'</em>); <i>// alerts <em>"Hi, Fred"</em></i>
125
126 <i>// create a <b>new</b> function that validates input without</i>
127 <i>// directly modifying the original <b>function</b>:</i>
128 <b>var</b> sayHiToFriend = sayHi.createInterceptor(<b>function</b>(name){
129     <b>return</b> name == <em>'Brian'</em>;
130 });
131
132 sayHiToFriend(<em>'Fred'</em>);  <i>// no alert</i>
133 sayHiToFriend(<em>'Brian'</em>); // alerts <em>"Hi, Brian"</em></code></pre>    <div class="mdetail-params">\r
134         <strong>Parameters:</strong>\r
135         <ul><li><code>fcn</code> : Function<div class="sub-desc">The function to call before the original</div></li><li><code>scope</code> : Object<div class="sub-desc">(optional) The scope of the passed fcn (Defaults to scope of original function or window)</div></li>        </ul>\r
136         <strong>Returns:</strong>\r
137         <ul>\r
138             <li><code>Function</code><div class="sub-desc">The new function</div></li>\r
139         </ul>\r
140     </div>\r
141                 </div>\r
142                         </div>\r
143         </td>\r
144         <td class="msource">Function</td>\r
145     </tr>\r
146         <tr class="method-row alt expandable">\r
147         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
148         <td class="sig">\r
149         <a id="Function-createSequence"></a>\r
150             <b>createSequence</b>(&nbsp;<code>Function fcn</code>, <span class="optional" title="Optional">[<code>Object scope</code>]</span>&nbsp;) : Function            <div class="mdesc">\r
151                         <div class="short">Create a combined function call sequence of the original function + the passed function.
152 The resulting function retur...</div>\r
153             <div class="long">\r
154                 Create a combined function call sequence of the original function + the passed function.
155 The resulting function returns the results of the original function.
156 The passed fcn is called with the parameters of the original function. Example usage:
157 <pre><code>var sayHi = <b>function</b>(name){
158     alert(<em>'Hi, '</em> + name);
159 }
160
161 sayHi(<em>'Fred'</em>); <i>// alerts <em>"Hi, Fred"</em></i>
162
163 <b>var</b> sayGoodbye = sayHi.createSequence(<b>function</b>(name){
164     alert(<em>'Bye, '</em> + name);
165 });
166
167 sayGoodbye(<em>'Fred'</em>); // both alerts show</code></pre>    <div class="mdetail-params">\r
168         <strong>Parameters:</strong>\r
169         <ul><li><code>fcn</code> : Function<div class="sub-desc">The function to sequence</div></li><li><code>scope</code> : Object<div class="sub-desc">(optional) The scope of the passed fcn (Defaults to scope of original function or window)</div></li>        </ul>\r
170         <strong>Returns:</strong>\r
171         <ul>\r
172             <li><code>Function</code><div class="sub-desc">The new function</div></li>\r
173         </ul>\r
174     </div>\r
175                 </div>\r
176                         </div>\r
177         </td>\r
178         <td class="msource">Function</td>\r
179     </tr>\r
180         <tr class="method-row expandable">\r
181         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
182         <td class="sig">\r
183         <a id="Function-defer"></a>\r
184             <b>defer</b>(&nbsp;<code>Number millis</code>, <span class="optional" title="Optional">[<code>Object obj</code>]</span>, <span class="optional" title="Optional">[<code>Array args</code>]</span>, <span class="optional" title="Optional">[<code>Boolean/Number appendArgs</code>]</span>&nbsp;) : Number            <div class="mdesc">\r
185                         <div class="short">Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
186 var say...</div>\r
187             <div class="long">\r
188                 Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
189 <pre><code>var sayHi = <b>function</b>(name){
190     alert(<em>'Hi, '</em> + name);
191 }
192
193 <i>// executes immediately:</i>
194 sayHi(<em>'Fred'</em>);
195
196 <i>// executes after 2 seconds:</i>
197 sayHi.defer(2000, <b>this</b>, [<em>'Fred'</em>]);
198
199 <i>// <b>this</b> syntax is sometimes useful <b>for</b> deferring</i>
200 <i>// execution of an anonymous <b>function</b>:</i>
201 (<b>function</b>(){
202     alert(<em>'Anonymous'</em>);
203 }).defer(100);</code></pre>    <div class="mdetail-params">\r
204         <strong>Parameters:</strong>\r
205         <ul><li><code>millis</code> : Number<div class="sub-desc">The number of milliseconds for the setTimeout call (if 0 the function is executed immediately)</div></li><li><code>obj</code> : Object<div class="sub-desc">(optional) The object for which the scope is set</div></li><li><code>args</code> : Array<div class="sub-desc">(optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)</div></li><li><code>appendArgs</code> : Boolean/Number<div class="sub-desc">(optional) if True args are appended to call args instead of overriding,
206 if a number the args are inserted at the specified position</div></li>        </ul>\r
207         <strong>Returns:</strong>\r
208         <ul>\r
209             <li><code>Number</code><div class="sub-desc">The timeout id that can be used with clearTimeout</div></li>\r
210         </ul>\r
211     </div>\r
212                 </div>\r
213                         </div>\r
214         </td>\r
215         <td class="msource">Function</td>\r
216     </tr>\r
217             </table>
218                 <a id="Function-events"></a>
219         <h2>Public Events</h2>
220         <div class="no-members">This class has no public events.</div>
221         </div>