代码之家  ›  专栏  ›  技术社区  ›  Homer

console.time()在IE8开发工具中

  •  14
  • Homer  · 技术社区  · 14 年前

    有一个等价于

    console.time('');
    console.timeEnd('');
    

    2 回复  |  直到 14 年前
        1
  •  42
  •   BillyTom warpech    11 年前

    没有,但您可以使用JavaScript轻松定义:

    // console.time implementation for IE
    if(window.console && typeof(window.console.time) == "undefined") {
        console.time = function(name, reset){
            if(!name) { return; }
            var time = new Date().getTime();
            if(!console.timeCounters) { console.timeCounters = {}; }
            var key = "KEY" + name.toString();
            if(!reset && console.timeCounters[key]) { return; }
                console.timeCounters[key] = time;
            };
    
        console.timeEnd = function(name){
            var time = new Date().getTime();
            if(!console.timeCounters) { return; }
            var key = "KEY" + name.toString();
            var timeCounter = console.timeCounters[key];
            var diff;
            if(timeCounter) {
                diff = time - timeCounter;
                var label = name + ": " + diff + "ms";
                console.info(label);
                delete console.timeCounters[key];
            }
            return diff;
        };
    }
    

    只需将它放在JS文件中,然后再使用控制台时间()和控制台.时间结束().

    这不是我的代码,我实际上是从Firebug核心复制的。

        2
  •  4
  •   Spudley Pat    14 年前

    如果你想在IE中使用Firebug,有一个叫做Firebug Lite的版本,可以在任何浏览器中作为“Bookmarklet”使用。

    http://getfirebug.com/firebuglite

    它没有真正的功能,但它可以做很多,所以它可能值得一试。

    推荐文章