On 04/04/11 12:21, Robert wrote:
I need to delay exit from js method. Normally I am using callbacks,
but I am working with some designers who do not really grasp the
concept.
So I started to think about a way to ease work for them but I am not
sure it is possible at all...
var test = 0;
var trigger= function(){ test = 1; };
trigger.delay(5000);
var main = function(){
while(test==0){
sleep(200);
}
return "TEST";
}
alert('start');
if(main()=='TEST'){
alert('end');
}
Is in mootools anything like sleep which would work in similar
context? Maybe some smart trick with delay or periodical?
Thanks,
Robert
I think I understand what and why you are trying to do what you are, but
it is INSIDE OUT from the way Javascript works. However, I had to solve
a similar issue recently where the problem was the degree of time taken
to do the calculations would cause the browser to report a lock up if I
didn't do something about it. In the end I discovered an invention by
Atsushi Oka (http://ats.oka.nu/index.en.html) which he called
Non-Structured Oriented Programming.
Unfortunately, because of his use of Object.prototype I couldn't get it
to play well with Mootools and invented a class which I called Nested
Closures Oriented Programming which does the same thing but in a much
simpler way and which is based on Mootools.
http://www.chandlerfamily.org.uk/2010/06/the-making-of-mbchat-v3-part-1-introducing-non-structured-programming/
I am not sure you could use what Atsushi Oka invented directly, but it
does seem its could be bent towards what you are trying to do.
----------
HOWEVER, I think I would go back harder to understand why designers
don't understand callbacks and see if you can use code layout to help
them understand. By that I mean
var req = new Request({ ...................onComplete:function(html) {
what happens when the request completes
}});
seems to me to be intuitive once you get it, why do they have problems?
--
Alan Chandler
http://www.chandlerfamily.org.uk