Properties Methods Events Direct Link

# Class Ext.util.Functions

Package: | Ext.util
Defined In: | Function.js
Class: | Functions
Extends: | Object

This class is a singleton and cannot be created directly.

## Public Properties

This class has no public properties.

## Public Methods

Method | Defined By
--- | ---
| createDelegate( `Function fn`, [`Object scope`], [`Array args`], [`Boolean/Number appendArgs`] ) : Function Creates a delegate (callback) that sets the scope to obj. Call directly on any function. Example: Ext.createDelegate(... Creates a delegate (callback) that sets the scope to obj. Call directly on any function. Example: `Ext.createDelegate(this.myFunction, this, [arg1, arg2])` Will create a function that is automatically scoped to obj so that the `this` variable inside the callback points to obj. Example usage:
    var sayHi = function(name){
        // Note this use of "this.text" here.  This function expects to
        // execute within a scope that contains a text property.  In this
        // example, the "this" variable is pointing to the btn object that
        // was passed in createDelegate below.
        alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
    }

    var btn = new Ext.Button({
        text: 'Say Hi',
        renderTo: Ext.getBody()
    });

    // This callback will execute in the scope of the
    // button instance. Clicking the button alerts
    // "Hi, Fred. You clicked the "Say Hi" button."
    btn.on('click', Ext.createDelegate(sayHi, btn, ['Fred']));
Parameters: `fn` : Function The function to delegate. `scope` : Object (optional) The scope (`this` reference) in which the function is executed. If omitted, defaults to the browser window. `args` : Array (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller) `appendArgs` : Boolean/Number (optional) if True args are appended to call args instead of overriding, if a number the args are inserted at the specified position Returns: `Function` The new function | Functions
| createInterceptor( `Function origFn`, `Function newFn`, [`Object scope`] ) : Function Creates an interceptor function. The passed function is called before the original one. If it returns false, the orig... Creates an interceptor function. The passed function is called before the original one. If it returns false, the original one is not called. The resulting function returns the results of the original function. The passed function is called with the parameters of the original function. Example usage:
    var sayHi = function(name){
        alert('Hi, ' + name);
    }

    sayHi('Fred'); // alerts "Hi, Fred"

    // create a new function that validates input without
    // directly modifying the original function:
    var sayHiToFriend = Ext.createInterceptor(sayHi, function(name){
        return name == 'Brian';
    });

    sayHiToFriend('Fred');  // no alert
    sayHiToFriend('Brian'); // alerts "Hi, Brian"
Parameters: `origFn` : Function The original function. `newFn` : Function The function to call before the original `scope` : Object (optional) The scope (`this` reference) in which the passed function is executed. If omitted, defaults to the scope in which the original function is called or the browser window. Returns: `Function` The new function | Functions
| createSequence( `Function origFn`, `Function newFn`, [`Object scope`] ) : Function Create a combined function call sequence of the original function + the passed function. The resulting function retur... Create a combined function call sequence of the original function + the passed function. The resulting function returns the results of the original function. The passed fcn is called with the parameters of the original function. Example usage: var sayHi = function(name){ alert('Hi, ' + name); } sayHi('Fred'); // alerts "Hi, Fred" var sayGoodbye = Ext.createSequence(sayHi, function(name){ alert('Bye, ' + name); }); sayGoodbye('Fred'); // both alerts show Parameters: `origFn` : Function The original function. `newFn` : Function The function to sequence `scope` : Object (optional) The scope (this reference) in which the passed function is executed. If omitted, defaults to the scope in which the original function is called or the browser window. Returns: `Function` The new function | Functions
| defer( `Function fn`, `Number millis`, [`Object scope`], [`Array args`], [`Boolean/Number appendArgs`] ) : Number Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage: var say... Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
    var sayHi = function(name){
        alert('Hi, ' + name);
    }

    // executes immediately:
    sayHi('Fred');

    // executes after 2 seconds:
    Ext.defer(sayHi, 2000, this, ['Fred']);

    // this syntax is sometimes useful for deferring
    // execution of an anonymous function:
    Ext.defer(function(){
        alert('Anonymous');
    }, 100);
Parameters: `fn` : Function The function to defer. `millis` : Number The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately) `scope` : Object (optional) The scope (`this` reference) in which the function is executed. If omitted, defaults to the browser window. `args` : Array (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller) `appendArgs` : Boolean/Number (optional) if True args are appended to call args instead of overriding, if a number the args are inserted at the specified position Returns: `Number` The timeout id that can be used with clearTimeout | Functions

## Public Events

This class has no public events.