Extjs Defer

extjs

http://www.sencha.com/forum/showthread.php?135499-Promises-and-Deferreds-Futures-in-Ext-JS
http://deftjs.org/
http://www.mattgoldspink.co.uk/2013/01/21/promises-in-ext-js-and-sencha-touch/

What is defer in ExtJS?

As of ExtJS 4.0.7, Defer in ExtJS is equivalent to setTimeout. It is not the same as the defer pattern as in other library.

What are the parameters accepted by defer?

defer( Function fn, Number millis, [Object scope], [Array args], [Boolean/Number appendArgs])
  1. fn : Function. The function to defer.
  2. millis : Number. The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
  3. scope : Object (optional) The scope (this reference) in which the function is executed. If omitted, defaults to the browser window.
  4. args : Array. (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
  5. 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

Examples of using defer:

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);

What is the value returned by defer?

This is a number, which is the timeout id that is returned by setTimeout. This can be used with clearTimeout

Ext.defer(function() {
    me.fireEvent('decorateForm');
    me.postRenderForm(sections);
}, 100);
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License