Search code examples
javascriptperformancecounter

Why can't I iterate over `performance.timing` using Underscore or lodash?


Why does this:

setTimeout(function(){
    var myObj = {
        'hello':'world',
        'more':'things'
    };
    
    _.each(myObj, function(value, key){
        console.log(key, value);
    });
    
    // why doesn't this output anything?    
    _.each(performance.timing, function(value, key){
        console.log(key, value);
    });
    
    // just to make sure we can
    console.log(performance.timing);
},500);
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>

output this:

> hello world
> more things
> PerformanceTiming {}

I would expect the object's keys and values to get output the same as myobj.

Underscore: http://jsfiddle.net/a43vb7gd/1/
lodash: http://jsfiddle.net/mkxncwax/1/

Reproduces on Chrome 43.0.2357.81 and Firefox 38.0 on Ubuntu 14.04.2 LTS.

screenshot of code and console output


Solution

  • Only thing I can think of is host object weirdness. Object.keys(performance.timing) returns and empty array. Also code behaves differently if it's run on the page vs run in the console.