我们应用程序中的错误(现已修复)代码触发了此错误:
TypeError: Cannot create property 'FOO' on string 'BAR'
但是 Javascript 完全允许在字符串变量上设置自由属性。我刚刚在 Chrome 控制台中尝试过:
'BAR'.FOO = 'hello'
'BAR'['FOO'] = 'hello'
而且效果很好。
那么 JS 解释器在什么情况下会触发这个错误?
原始代码是用 Typescript 编写的,然后用 Babel 转译。这是一个运行时错误。我认为这与 typescript 无关,因为其他人报告了类似的运行时错误,例如。 here和 here
最佳答案
So in which context do the JS interpreter trigger this error ?
'use strict';
'BAR'.FOO = 'test';
关于javascript - 类型错误 : Cannot create property 'FOO' on string 'BAR' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37393656/