PDA

View Full Version : Defer + scope



asti
24 Jul 2012, 12:49 AM
I have a problem regarding scope in Ext.defer

I'm trying to get the GUI more responsive. But when it comes to calling process(... , the scope in process is DOMWindow and not my requested scope.

It would be glad to get some hints...


function timedProcessArray(items, process, scope, callback){
var todo = items.concat(); // Kopie fuer Abarbeitung

Ext.defer(function(){
var end, start = new Date();
do {
process(todo.shift());
end = new Date();
} while (todo.length > 0 && (end - start) < 50 );
if ( todo.length > 0){
Ext.defer(arguments.callee, 25, scope);
}
else {
callback(items);
}
},25,scope);
}

evant
24 Jul 2012, 12:57 AM
That's right. If process is a global function the scope will always be the window unless you specify otherwise:



process.call(scope, todo.shift());

asti
24 Jul 2012, 1:08 AM
What i actually want do is appending child nodes to a Gridtree.


timedProcessArray(value, node.appendChild, node, function(){
console.log("timed processing done");
});

Ok, thanks, your suggestion with process.call( scope ...) works.