On Jun 26, 9:01 pm, Emil <e...@poczta.onet.plwrote:
Is it posiible to create callback for a function, that is automatically
called before that function returns? I need it for tracing/profiling
purposes.
Not in the way you want - javascript is single threaded. You can use
setTimeout to run a function at some later time, but:
1. It will not start until the current function is finished
2. If some other javscript function is running when the time
is up, it will wait at least until that function has finished
You may be able to do what you want using a wrapper that calls other
functions and times how long they take, e.g.
function timingWrapper(func0, func1, ...){
var s0, s1, s2, ...
var f0, f1, f2, ...
// Time first function
s0 = new Date();
func0();
f0 = new Date();
// Time second function
s1 = new Date();
func1();
f1 = new Date();
...
alert('1st took ' + (f0-s0) + ' milliseconds'
+ '\n2nd took ' + (f1-s1) + ' milliseconds'
+ ...
);
}
You can extend that approach using an object that stores required
values and calls itself (maybe using setTimeout) when functions are
finished. You can also run stuff in an iframe to get a kind of
isolated environment.
Have a look at the techniques applied here:
<URL:
http://mootools.net/slickspeed/ >
--
Rob