我们的应用程序中的错误(现在已修复)代码触发了此错误:
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';
更多推荐
发布评论