Tuesday, June 21, 2011

JS: вызывать проверку с таймаутом, пока деревянная лошадка не пукнет.

И не срем в глобальную область видимости:
  1. (function (i, start, iterations) {
  2.     (function () {
  3.         if (i < iterations) {
  4.             i++;
  5.             setTimeout.call(this, arguments.callee, 1);
  6.         } else {
  7.             alert(i + ' iterations took ' + ((+new Date()) - start) + 'ms');
  8.         }
  9.     })();
  10. })(0, +new Date(), 500);
* This source code was highlighted with Source Code Highlighter.

Labels: ,

0 Comments:

Post a Comment

<< Home