TypeError:无法在字符串'BAR'上创建属性'FOO'(TypeError: Cannot create property 'FOO'

编程入门 行业动态 更新时间:2024-10-25 22:24:41
TypeError:无法在字符串'BAR'上创建属性'FOO'(TypeError: Cannot create property 'FOO' on string 'BAR')

我们的应用程序中的错误(现在已修复)代码触发了此错误:

TypeError: Cannot create property 'FOO' on string 'BAR'

但Javascript完全允许设置字符串变量的自由属性。 我只是在Chrome控制台中试过它:

'BAR'.FOO = 'hello' 'BAR'['FOO'] = 'hello'

而且效果很好。

那么在哪个上下文中,JS解释器会触发这个错误?

原始代码用Typescript编写,然后用Babel编译。 这是运行时错误。 我认为这与打字稿无关,因为其他人报告类似的运行时错误,例如。 在这里和这里

A wrong (and now fixed) code in our app triggered this error :

TypeError: Cannot create property 'FOO' on string 'BAR'

But Javascript completely allows setting free properties on a string variable. I just tried it in Chrome console :

'BAR'.FOO = 'hello' 'BAR'['FOO'] = 'hello'

And it works perfectly.

So in which context do the JS interpreter trigger this error ?

The original code is written in Typescript, then transpiled with Babel. This is a runtime error. I assume this is not related to typescript since other people report a similar runtime error, ex. here and here

最满意答案

那么JS解释器在哪个上下文中触发了这个错误?

严格模式 。

'use strict';
'BAR'.FOO = 'test'; 
  
 

So in which context do the JS interpreter trigger this error ?

Strict mode.

'use strict';
'BAR'.FOO = 'test'; 
  
 

更多推荐

本文发布于:2023-08-07 11:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464282.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   属性   BAR   TypeError   string

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!