2013-11-04 28 views
0

谷歌瀏覽器調試器控制檯:的Javascript定製的console.log

var array = ['item1']; 
array //will print ["item1"] 

Object.defineProperty(array, '1', {get: function(){return 'item2';}, set: function(v){}}); 
array //will print nothing 

有沒有一種方法,使最後一行打印一些信息? console.log(數組)也可以打印['item1']。 我只是爲了調試目的而需要它。

這實際上在Firefox中正常工作。在Safari中我得到[「item1」,undefined×1]。

+0

在Opera上運行良好。你用什麼'console'工具(什麼瀏覽器,什麼版本)? – Bergi

+0

嘗試'Object.defineProperty(array,'1',{enumerable:true,...})' – Bergi

+0

看看這個問題[Javascript - 覆蓋console.log並保留舊函數](http://stackoverflow.com/questions-15657607/javascript-override-console-log-and-keep-the-old-function) – shawnzhu

回答

2

如果您使用的是chrome,請嘗試console.dir(array)。