Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript TypeError:无法添加属性_id,对象不可扩展_Javascript_Reactjs - Fatal编程技术网

JavaScript TypeError:无法添加属性_id,对象不可扩展

JavaScript TypeError:无法添加属性_id,对象不可扩展,javascript,reactjs,Javascript,Reactjs,我定义了一个HOC React组件并将其保存为一个tsx文件 const Hoc = WrappedComponent => class extends WrappedComponent { constructor(props, context) { super(props, context) this.__id = '' } } 一旦将其交付给编译器,就会抛出错误 TypeError: Cannot add property __id, object is n

我定义了一个HOC React组件并将其保存为一个tsx文件

const Hoc = WrappedComponent => class extends WrappedComponent {

  constructor(props, context) {
    super(props, context)
    this.__id = ''
  }
}
一旦将其交付给编译器,就会抛出错误

TypeError: Cannot add property __id, object is not extensible

错误来自为
WrappedComponent
参数传递的任何参数。以下内容不会引发:
const Hoc=WrappedComponent=>类扩展WrappedComponent{constructor(props,context){super(props,context);this.\uu id='';}
然后
new Hoc(class{})
错误来自为
WrappedComponent
参数传递的任何参数。以下内容不会引发:
const Hoc=WrappedComponent=>类扩展WrappedComponent{constructor(props,context){super(props,context);this.\uu id='';}然后
新建Hoc(类{})