TypeError: can't convert console.log(...) to primitive type
一、背景
火狐浏览器提示这个错误,谷歌没有。
二、出错代码
var eventHandlers = {
'succeeded': function(e){
console.log('send success' + e.cause)
},
'failed': function(e){
console.log('send failed,reason='+e.cause)
}
};
三、原因
火狐处理console.log('send success' + e.cause)的时候,会默认把e.cause转换成String类型,所以提示如题的错误。
四、解决办法
不适用字符串拼接的方式,直接打印。
五、修订后的代码
var eventHandlers = {
'succeeded': function(e){
console.log(e.cause),
console.log('send success')
},
'failed': function(e){
console.log('send failed,reason'),
console.log(e.cause)
}
};
六、测试结果
错误消除。
TypeError: can't convert console.log(...) to primitive type的更多相关文章
- console.log的另一种用法
// console.log用法 var foo, bar; console.log(`foo's type: ${foo}`, `bar's type: ${bar}`); 输出:
- JS里try...catch...finally详解,以及console日志调试(console.log、console.info等)
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- js console.log all in one
js console.log all in one this & arguments "use strict"; /** * * @author xgqfrms * @li ...
- const let,console.log('a',a)跟console.log('a'+a)的区别
const 创建一个只读的常量 let块级作用域 const let重复赋值都会报错 console.log('a',a) a console.log('a'+a) a2 逗号的值会有空格:用加号的值 ...
- console.log("A"-"B"+"3")=?
(点击上方的订阅号,可快速关注,关注有惊喜哦^_^) 前不久看到一道JS基础题目,做了一下竟然错了一半...在此分享一下: 先把题目放上来,大家可以自己测试一下再看答案哦^_^ ①console.lo ...
- javascript的console.log用法
f1.html代码 <iframe id="frame2" name="frame1" src="ww.html"></i ...
- alert()与console.log()的区别
[1]alert() [1.1]有阻塞作用,不点击确定,后续代码无法继续执行 [1.2]alert()只能输出string,如果alert输出的是对象会自动调用toString()方法 e.g. al ...
- console.log((function f(n){return ((n > 1) ? n * f(n-1) : n)})(5))调用解析
console.log((function f(n){) ? n * f(n-) : n)})()); 5被传入到函数,函数内部三元计算,5 > 1成立,运算结果是5*f(4),二次运算,5*4 ...
- JS高级群的日常!写一个从10到0的倒计时,用console.log打印,不可以用 setInterval!本来说好的研究avalonJS最后演变成了看着大神在那边互相比拼实力。。
JS高级群的日常!写一个从10到0的倒计时,用console.log打印,不可以用 setInterval!本来说好的研究avalonJS最后演变成了看着大神在那边互相比拼实力.. 小森执行一 ...
随机推荐
- Configuring spartan 6 using mcu and spi flash
http://forums.xilinx.com/t5/General-Technical-Discussion/Configuring-spartan-6-using-mcu-and-spi-fla ...
- .NET 4.5 is an in-place replacement for .NET 4.0
With the betas for .NET 4.5 and Visual Studio 11 and Windows 8 shipping many people will be installi ...
- Ubuntu OS应用Runtime Enviroment
在这篇文章中.我们将介绍Ubuntu OS的Runtime Environment.在文章"App confinement: Security policy for click packag ...
- C#类和结构体的异同点简单总结
类和结构的异同点?异: 1.关键字不同 一个是class,一个是struct 2.类型不同,一个是引用类型,一个是值类型(一个堆区,一个栈区) 3.成员不同,结构体没有默认的构造函数 ...
- vc预处理
VC 编译命令开关 vc可以可以通过Settings -->Project-->C/C++-->Customize来设置这个编译开关 /C:在预处理输出中保留注释语句 /c:只编译, ...
- js 中三层引号问题
方式1: '[{"Company": "XYZ","Description": "\"TEST\"" ...
- CUDA使用Event进行程序计时
GPGPU是众核设备,包含大量的计算单元,实现超高速的并行. 使用CUDA在nvidia显卡上面编程时,可以使用CUDA提供的Event进行程序计时. 当然,每种编程语言基本都提供了获取系统时间的函数 ...
- Servlet介绍以及简单实例
一.背景介绍: HTTP:超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.设计HTTP最初的目的是为了提供一种发布和接收 HTM ...
- Python requests 报错解决集锦
python版本号和ssl版本号都会导致 requests在请求https站点时候会出一些错误,最好使用新版本号. 1 Python2.6x use requests 一台老Centos机器上跑着古老 ...
- (1)风色从零单排《C++ Primer》 一个简单的c++程序
从零单排<C++ Primer> --(1)一个简单的c++程序 本次学习收获 0.写在前面 风色以前上过C++的课程,然而当时并没有认真去学,基本不能使用c++来作项目开发. 这次又一次 ...