这是 ES6 问题的一部分,React 问题的一部分。我正在尝试使用命名空间组件 https://facebook.github.io/react/docs/jsx-in-depth.html#namespaced-components在 React 中使用 ES6 类和 Babel。所以我想真正的问题是如何命名空间 es6 类,这样我就可以执行这里解释的操作:https://facebook.github.io/react/docs/jsx-in-deep.html#namespaced-components https://facebook.github.io/react/docs/jsx-in-depth.html#namespaced-components
由于我收到意外的令牌错误:
class Headline extends Component { ... }
class Headline.Primary extends Component { ...
^
The ECMAScript-6 类声明 http://www.ecma-international.org/ecma-262/6.0/index.html#sec-class-definitions语法需要一个标准绑定标识符作为类名。点不是标识符名称中的有效字符。
在OP中链接使用的上下文中,“命名空间”是一个对象,并且使用点表示法将属性一一添加到该对象中以进行属性访问。
您可以通过使用来复制它类表达式反而:
'use strict'
var ns = {}
ns.MyClass = class {
constructor() {
console.log('in constructor')
}
}
new ns.MyClass()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)