• Timed Code


    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script>
            "use strict";
            function timedProcessArray(items, process, callback) {
                var todo = items.concat();   //create a clone of the original
                setTimeout(function doSmall() {
                    var start = +new Date();
                    do {
                        process(todo.shift());
                    } while (todo.length > 0 && (+new Date() - start < 50));
                    if (todo.length > 0) {
                        setTimeout(doSmall, 25);
                    } else {
                        callback(items);
                    }
                }, 25);
            }
    
            function dothing() {
                timedProcessArray([dothings1, dothings2],
                    function(f) {
                         f();
                    },
                    function() {
                         console.log('done1');
                    });
            }
    
            function dothings1() {
                console.log('dothings1')
            }
    
            function dothings2() {
                console.log('dothings2')
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div onclick="dothing()">
        hello
        </div>
        </form>
    </body>
    </html>

    http://www.nczonline.net/blog/2009/08/11/timed-array-processing-in-javascript/

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments/callee

  • 相关阅读:
    排序二——交换排序
    桥接模式 Bridge
    外观模式Facade(解耦)
    装饰模式和代理模式的区别
    代理模式 proxy
    装饰器模式 Decorator
    适配器模式
    android launcher-启动过程
    ubuntu 编译openwrt
    Eclipse Memory Analyzer tool(MAT)
  • 原文地址:https://www.cnblogs.com/joe-yang/p/3721140.html
Copyright © 2020-2023  润新知