在Javascript中,对象上的console.log是否调用toString? [英] In Javascript, does console.log on an object call toString?

查看:367
本文介绍了在Javascript中,对象上的console.log是否调用toString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Array.prototype.toString = function(){
    return "testing";
}

a1 = [1,2,3];

console.log(a1); // returns [1,2,3]
console.log(a1.toString()); // returns "testing"

为什么?第一个日志如何打印出值?我以为它使用了toString方法?

why is that? How does the first log print out values? I thought it used the toString method?

推荐答案

对于Firefox(Firebug和Dev Web Console),Chrome:否

For Firefox(both Firebug and Dev Web Console), Chrome: No

对于IE:是

这篇关于在Javascript中,对象上的console.log是否调用toString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆