This is part ES6 question part React question. I'm trying to use namespaced components in React with ES6 classes and Babel. So I guess the real question is how to name space es6 classes so I can do what is explained here: https://facebook.github.io/react/docs/jsx-in-depth.html#namespaced-components
Since I get an unexpected token error:
class Headline extends Component { ... } class Headline.Primary extends Component { ... ^
Using an ES6 class to write the same component is a little different. Instead of using a method from the react library, we extend an ES6 class that the library defines, Component . constructor() is a special function in a JavaScript class. JavaScript invokes constructor() whenever an object is created via a class.
ES6 introduced classes. A class is a type of function, but instead of using the keyword function to initiate it, we use the keyword class , and the properties are assigned inside a constructor() method.
In the context used in the link in OP, the "namespace" is an object, and properties are added to that object one by one using the dot notation for property access. You could replicate that by using a class expression instead: 'use strict' var ns = {} ns. MyClass = class { constructor() { console.
class Counter extends React. Component { constructor(props) { super(props); this.
The ECMAScript-6 class declaration syntax expects a standard BindingIdentifer as the class name. A dot is not a valid character inside an identifier name.
In the context used in the link in OP, the "namespace" is an object, and properties are added to that object one by one using the dot notation for property access.
You could replicate that by using a class expression instead:
'use strict' var ns = {} ns.MyClass = class { constructor() { console.log('in constructor') } } new ns.MyClass()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With