3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.util.Functions"></div>/**
16 * @class Ext.util.Functions
19 Ext.util.Functions = {
20 <div id="method-Ext.util.Functions-createInterceptor"></div>/**
21 * Creates an interceptor function. The passed function is called before the original one. If it returns false,
22 * the original one is not called. The resulting function returns the results of the original function.
23 * The passed function is called with the parameters of the original function. Example usage:
25 var sayHi = function(name){
29 sayHi('Fred'); // alerts "Hi, Fred"
31 // create a new function that validates input without
32 // directly modifying the original function:
33 var sayHiToFriend = Ext.createInterceptor(sayHi, function(name){
34 return name == 'Brian';
37 sayHiToFriend('Fred'); // no alert
38 sayHiToFriend('Brian'); // alerts "Hi, Brian"
40 * @param {Function} origFn The original function.
41 * @param {Function} newFn The function to call before the original
42 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
43 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
44 * @return {Function} The new function
46 createInterceptor: function(origFn, newFn, scope) {
48 if (!Ext.isFunction(newFn)) {
56 newFn.method = origFn;
57 return (newFn.apply(scope || me || window, args) !== false) ?
58 origFn.apply(me || window, args) :
64 <div id="method-Ext.util.Functions-createDelegate"></div>/**
65 * Creates a delegate (callback) that sets the scope to obj.
66 * Call directly on any function. Example: <code>Ext.createDelegate(this.myFunction, this, [arg1, arg2])</code>
67 * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
68 * callback points to obj. Example usage:
70 var sayHi = function(name){
71 // Note this use of "this.text" here. This function expects to
72 // execute within a scope that contains a text property. In this
73 // example, the "this" variable is pointing to the btn object that
74 // was passed in createDelegate below.
75 alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
78 var btn = new Ext.Button({
80 renderTo: Ext.getBody()
83 // This callback will execute in the scope of the
84 // button instance. Clicking the button alerts
85 // "Hi, Fred. You clicked the "Say Hi" button."
86 btn.on('click', Ext.createDelegate(sayHi, btn, ['Fred']));
88 * @param {Function} fn The function to delegate.
89 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
90 * <b>If omitted, defaults to the browser window.</b>
91 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
92 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
93 * if a number the args are inserted at the specified position
94 * @return {Function} The new function
96 createDelegate: function(fn, obj, args, appendArgs) {
97 if (!Ext.isFunction(fn)) {
101 var callArgs = args || arguments;
102 if (appendArgs === true) {
103 callArgs = Array.prototype.slice.call(arguments, 0);
104 callArgs = callArgs.concat(args);
106 else if (Ext.isNumber(appendArgs)) {
107 callArgs = Array.prototype.slice.call(arguments, 0);
108 // copy arguments first
109 var applyArgs = [appendArgs, 0].concat(args);
110 // create method call params
111 Array.prototype.splice.apply(callArgs, applyArgs);
114 return fn.apply(obj || window, callArgs);
118 <div id="method-Ext.util.Functions-defer"></div>/**
119 * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
121 var sayHi = function(name){
122 alert('Hi, ' + name);
125 // executes immediately:
128 // executes after 2 seconds:
129 Ext.defer(sayHi, 2000, this, ['Fred']);
131 // this syntax is sometimes useful for deferring
132 // execution of an anonymous function:
133 Ext.defer(function(){
137 * @param {Function} fn The function to defer.
138 * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
139 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
140 * <b>If omitted, defaults to the browser window.</b>
141 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
142 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
143 * if a number the args are inserted at the specified position
144 * @return {Number} The timeout id that can be used with clearTimeout
146 defer: function(fn, millis, obj, args, appendArgs) {
147 fn = Ext.util.Functions.createDelegate(fn, obj, args, appendArgs);
149 return setTimeout(fn, millis);
156 <div id="method-Ext.util.Functions-createSequence"></div>/**
157 * Create a combined function call sequence of the original function + the passed function.
158 * The resulting function returns the results of the original function.
159 * The passed fcn is called with the parameters of the original function. Example usage:
162 var sayHi = function(name){
163 alert('Hi, ' + name);
166 sayHi('Fred'); // alerts "Hi, Fred"
168 var sayGoodbye = Ext.createSequence(sayHi, function(name){
169 alert('Bye, ' + name);
172 sayGoodbye('Fred'); // both alerts show
174 * @param {Function} origFn The original function.
175 * @param {Function} newFn The function to sequence
176 * @param {Object} scope (optional) The scope (this reference) in which the passed function is executed.
177 * If omitted, defaults to the scope in which the original function is called or the browser window.
178 * @return {Function} The new function
180 createSequence: function(origFn, newFn, scope) {
181 if (!Ext.isFunction(newFn)) {
186 var retval = origFn.apply(this || window, arguments);
187 newFn.apply(scope || this || window, arguments);
195 * Shorthand for {@link Ext.util.Functions#defer}
196 * @param {Function} fn The function to defer.
197 * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
198 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
199 * <b>If omitted, defaults to the browser window.</b>
200 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
201 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
202 * if a number the args are inserted at the specified position
203 * @return {Number} The timeout id that can be used with clearTimeout
208 Ext.defer = Ext.util.Functions.defer;
211 * Shorthand for {@link Ext.util.Functions#createInterceptor}
212 * @param {Function} origFn The original function.
213 * @param {Function} newFn The function to call before the original
214 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
215 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
216 * @return {Function} The new function
221 Ext.createInterceptor = Ext.util.Functions.createInterceptor;
224 * Shorthand for {@link Ext.util.Functions#createSequence}
225 * @param {Function} origFn The original function.
226 * @param {Function} newFn The function to sequence
227 * @param {Object} scope (optional) The scope (this reference) in which the passed function is executed.
228 * If omitted, defaults to the scope in which the original function is called or the browser window.
229 * @return {Function} The new function
234 Ext.createSequence = Ext.util.Functions.createSequence;
236 <div id="method-Ext-defer"></div>/**
237 * Shorthand for {@link Ext.util.Functions#createDelegate}
238 * @param {Function} fn The function to delegate.
239 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
240 * <b>If omitted, defaults to the browser window.</b>
241 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
242 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
243 * if a number the args are inserted at the specified position
244 * @return {Function} The new function
248 Ext.createDelegate = Ext.util.Functions.createDelegate;