this is my javascript test code:
(这是我的javascript测试代码:)
console.log( [] == 'a' );
when running in my firefox it gives this error: "TypeError: can't convert [] to primitive type"
(在我的Firefox中运行时,出现以下错误:“ TypeError:无法将[]转换为原始类型”)
what does this mean?
(这是什么意思?)
It does not seem to apply to every browser/browser version, or in my case, even a tab.(它似乎并不适用于所有浏览器/浏览器版本,或者就我而言,甚至不适用于选项卡。)
I have two chrome tabs open, if I try the code in one it gives an error, but in the other tab it works fine - making me very confused about the inconsistency.
(我打开了两个Chrome标签,如果我在其中一个尝试了代码,则会出错,但在另一个标签中,它可以正常工作-使我对不一致感到困惑。)
Here is an image showing the errors
(这是显示错误的图像)
So what am I missing here, why the inconsistency on chrome?
(那么,我在这里想念的是什么,为什么chrome不一致?)
Any help appreciated!(任何帮助表示赞赏!)
(EDIT 1) I've found that the error comes when adding/changing a bunch of prototypes onto the Array object, so how can I add prototypes without causing this error?
((编辑1)我发现在Array对象上添加/更改一堆原型时会出现错误,因此如何添加原型而不引起此错误?)
{ // if I omit the first line, the error does not occur Array.prototype.join = Array.prototype.concat; console.log( [] == 'a' ); }
ask by SSJCoder translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…