最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What's the difference between FireBug's console.log() and console.debug()? - Stack Overflow

programmeradmin2浏览0评论

A very simple code to illustrate the difference.

var x = [0, 3, 1, 2];
console.debug('debug', x);
console.log('log', x);
// above display the same result
x.splice(1, 2);
// below display kind of a different result
console.debug('debug', x);
console.log('log', x);

alt text .png

The javascript value is exactly the same but console.log() displays it a bit differently than before applying splice() method. Because of this I lost quite a few hours as I thought splice is acting funny making my array multidimensional or something.

I just want to know why does this work like that. Does anyone know? :)

A very simple code to illustrate the difference.

var x = [0, 3, 1, 2];
console.debug('debug', x);
console.log('log', x);
// above display the same result
x.splice(1, 2);
// below display kind of a different result
console.debug('debug', x);
console.log('log', x);

alt text http://sixbytesunder./stuff/firebug_console.png

The javascript value is exactly the same but console.log() displays it a bit differently than before applying splice() method. Because of this I lost quite a few hours as I thought splice is acting funny making my array multidimensional or something.

I just want to know why does this work like that. Does anyone know? :)

Share Improve this question edited Jun 18, 2010 at 20:16 Tyler 22.1k11 gold badges65 silver badges92 bronze badges asked Jun 16, 2010 at 12:36 6bytes6bytes 6,1329 gold badges39 silver badges44 bronze badges 1
  • As Tim writes below: “More likely is that console.log and console.debug simply behave differently by design. The source is available if you're curious.” You can also ask a question at Firebug's discussion group or file a bug report. – Marcel Korpel Commented Jun 16, 2010 at 14:08
Add a ment  | 

2 Answers 2

Reset to default 8

If you look at the documentation, it says:

The console knows four different types of messages, which are described below […]

See also the Console API for more information about the different mands.

A look on that page shows at console.log:

If objects are logged, they will be written not as static text, but as interactive hyperlinks that can be clicked to inspect the object in Firebug's HTML, CSS, Script, or DOM tabs.

So, I think that before the splice, the array is internally still an Array (I know, it is a kind of object), but after the operation, you get a general object, at least internally. I know this is a weak explanation, but Firebug has more strange behaviour in the console.

BTW, the ECMAScript specification says nothing useful, but we can read in the section about Array.prototype.splice (§ 15.4.4.12):

The splice function is intentionally generic; it does not require that its this value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method. Whether the splice function can be applied successfully to a host object is implementation-dependent.

In Firebug 1.6a12 I get

debug [0, 3, 1, 2]  blog.php (line 80)
log [0, 3, 1, 2]
debug [0, 2]        blog.php (line 85)
log [0, 2]

The debug() lines include a link to the source line of the console.debug() line.

发布评论

评论列表(0)

  1. 暂无评论