alert()返回与console.log()不同吗? [英] alert() return different from console.log()?

查看:57
本文介绍了alert()返回与console.log()不同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该使用alert()进行调试吗?还是有时间使用alert()与console.log()?

Should I be using alert() for debugging; or is there a time to use alert() vs. console.log()?

我看到alert()和console.log()可以返回不同的结果.我以为它们是相似的函数,只是在不同的地方返回.

I see that alert() and console.log() can return different results. I assumed that they were similar functions but just returned in different places.

背景故事:我的老板喜欢在开发过程中查看alert(),但是我无法(至少不容易)在警报中获得对象的详细信息.

Back story: my boss likes to see alerts() during development but I can't get the object details in the alert (at least not easily).

但是当我通过console.log运行相同的请求时,我得到了对象及其所有参数.

But when I run the same request through console.log, I get the object and all of it's parameters.

推荐答案

由于可以向用户显示警报,因此警报往往是字面意义(仅使用toString),因此开发人员可以对显示的内容进行很多控制用户.与Alert不同,控制台是为开发人员设计的,因此倾向于尝试解释呼叫,以便提供开发人员认为有用的信息:对开发人员而言,"[2、3、4]"比"[object Object]"有用得多.警报在每个浏览器中都应该相同;控制台的行为可能因浏览器而异(包括完全不受IE支持).

Since alert could be shown to users, it tends to be literal-minded (just using toString) so a developer has a lot of control over what's shown to the user. Unlike alert, console is designed for developers, and thus tends to try to interpret a call so as to provide information that a developer would find useful: e.g. "[2, 3, 4]" is a lot more useful to a developer than "[object Object]". Alert should be the same in every browser; console's behavior could vary from browser to browser (including not being supported at all, as in IE).

这篇关于alert()返回与console.log()不同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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