JSLint 认可的将数字转换为字符串的方法是什么?

2024-02-29

我总是通过向数字添加空字符串来将数字转换为字符串:

var string = 1 + '';

然而,JSLint 抱怨这种方法Expected 'String' and instead saw ''''.,而且看起来确实有点难看。

有没有更好的办法?


我相信 JSLint 批准的方式是调用.toString()关于号码:

var stringified = 1..toString();
// Note the use of the double .. to ensure the the interpreter knows 
// that we are calling the toString method on a number -- 
// not courting a syntax error.
// You could also theoretically call 1["toString"];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JSLint 认可的将数字转换为字符串的方法是什么? 的相关文章

随机推荐