Is there a method I can override on a JavaScript object to control what is displayed by console.log?

后端 未结 4 1036
旧时难觅i
旧时难觅i 2020-12-07 01:29

I\'m thinking in particular of Chrome, though Firebug would be interesting to. I\'ve tried toString() and valueOf(), but neither of those seem to be used. Interestingly, i

4条回答
  •  没有蜡笔的小新
    2020-12-07 01:31

    You should get a better result from Firebug, you should get

    var a = function(){};
    console.log(a); // output: function 
    a.toString = function(){ return 'a'; };
    console.log(a); // output: function, {toString()}
    a.valueOf = function(){ return 'v'; };
    console.log(a); // output: function, {toString(), valueOf()}
    

    http://code.google.com/p/fbug/issues/detail?id=3117

提交回复
热议问题