console.time() in IE8 Developer Tools

老子叫甜甜 提交于 2019-12-02 17:18:11
warpech

There isn't, but you can define it easily with 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;
    };
}

Just place it in your JS file before you want to use console.time() and console.timeEnd().

It is not my code, I actually copied it from Firebug core.

If you want to use Firebug in IE, there is a version called Firebug Lite, which can be used in any browser as a 'Bookmarklet'.

http://getfirebug.com/firebuglite

It isn't as functional as the real thing, but it can do a lot so it may be worth a try.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!