Clear Up
SharpKit Reference

Function Class

A collection of useful static methods to deal with function callbacks

Namespace: Ext

Base Types

System.Object

Methods

Name Description
alias(object, JsString) Create an alias to the provided method property with name methodName of object. Note that the execution scope will still be bound to the provided object itself.
bind(Delegate, object, object, object) Create a new function from the provided fn, change this to the provided scope, optionally overrides arguments for the call. (Defaults to the arguments passed by the caller) Ext.bind is alias for Ext.Function.bind
clone(Delegate) Create a "clone" of the provided method. The returned method will call the given method passing along all arguments and the "this" pointer and return its result.
createBuffered(Delegate, JsNumber, object, object) Creates a delegate function, optionally with a bound scope which, when called, buffers the execution of the passed function for the configured number of milliseconds. If called again within that period, the impending invocation will be canceled, and the timeout period will begin again.
createDelayed(Delegate, object, object, object, object) Creates a delegate (callback) which, when called, executes after a specific delay.
createInterceptor(Delegate, Delegate, object, object) 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.Function.createInterceptor(sayHi, function(name){
            return name == 'Brian';
            });
            sayHiToFriend('Fred');  // no alert
            sayHiToFriend('Brian'); // alerts "Hi, Brian"
            
createSequence(Delegate, Delegate, object) 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 function 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.Function.createSequence(sayHi, function(name){
            alert('Bye, ' + name);
            });
            sayGoodbye('Fred'); // both alerts show
            
createThrottled(Delegate, JsNumber, object) Creates a throttled version of the passed function which, when called repeatedly and rapidly, invokes the passed function only after a certain interval has elapsed since the previous invocation. This is useful for wrapping functions which may be called repeatedly, such as a handler of a mouse move event when the processing is expensive.
defer(Delegate, JsNumber, object, object, object) 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.Function.defer(sayHi, 2000, this, ['Fred']);
            // this syntax is sometimes useful for deferring
            // execution of an anonymous function:
            Ext.Function.defer(function(){
            alert('Anonymous');
            }, 100);
            
Ext.defer is alias for Ext.Function.defer
flexSetter(Delegate) A very commonly used method throughout the framework. It acts as a wrapper around another method which originally accepts 2 arguments for name and value. The wrapped function then allows "flexible" value setting of either:
  • name and value as 2 arguments
  • one single object argument with multiple key - value pairs
  • For example:
    var setValue = Ext.Function.flexSetter(function(name, value) {
                this[name] = value;
                });
                // Afterwards
                // Setting a single name - value
                setValue('name1', 'value1');
                // Settings multiple name - value pairs
                setValue({
                name1: 'value1',
                name2: 'value2',
                name3: 'value3'
                });
                
    interceptAfter(object, JsString, Delegate, object) Adds behavior to an existing method that is executed after the original behavior of the function. For example:
    var soup = {
                contents: [],
                add: function(ingredient) {
                this.contents.push(ingredient);
                }
                };
                Ext.Function.interceptAfter(soup, "add", function(ingredient){
                // Always add a bit of extra salt
                this.contents.push("salt");
                });
                soup.add("water");
                soup.add("onions");
                soup.contents; // will contain: water, salt, onions, salt
                
    interceptBefore(object, JsString, Delegate, object) Adds behavior to an existing method that is executed before the original behavior of the function. For example:
    var soup = {
                contents: [],
                add: function(ingredient) {
                this.contents.push(ingredient);
                }
                };
                Ext.Function.interceptBefore(soup, "add", function(ingredient){
                if (!this.contents.length && ingredient !== "water") {
                // Always add water to start with
                this.contents.push("water");
                }
                });
                soup.add("onions");
                soup.add("salt");
                soup.contents; // will contain: water, onions, salt
                
    pass(Delegate, object, object) Create a new function from the provided fn, the arguments of which are pre-set to args. New arguments passed to the newly created callback when it's invoked are appended after the pre-set ones. This is especially useful when creating callbacks. For example:
    var originalFunction = function(){
                alert(Ext.Array.from(arguments).join(' '));
                };
                var callback = Ext.Function.pass(originalFunction, ['Hello', 'World']);
                callback(); // alerts 'Hello World'
                callback('by Me'); // alerts 'Hello World by Me'
                
    Ext.pass is alias for Ext.Function.pass
    © Copyright 2005-2011 SharpKit. All rights reserved.