What does calling super() in a React constructor do?

super() will call the constructor of its parent class. This is required when you need to access some variables from the parent class. In React, when you call super with props, React will make props available across the component through this.props. See example 2 below without super() class A { constructor() { this.a=”hello” } } … Read more

How do I make a “public static field” in an ES6 class?

You make “public static field” using accessor and a “static” keyword: class Agent { static get CIRCLE() { return 1; } static get SQUARE() { return 2; } } Agent.CIRCLE; // 1 Looking at a spec, 14.5 — Class Definitions — you’d see something suspiciously relevant 🙂 ClassElement[Yield] :   MethodDefinition[?Yield]   static MethodDefinition[?Yield] ; So from … Read more

Template Strings ES6 prevent line breaks

This is insane. Almost every single answer here suggest running a function runtime in order to well-format, buildtime bad-formatted text oO Am I the only one shocked by that fact, especially performance impact ??? As stated by @dandavis, the official solution, (which btw is also the historic solution for unix shell scripts), is to escape … Read more

Are JavaScript ES6 Classes of any use with asynchronous code bases?

Can I do async constructor() No, that’s a syntax error – just like constructor* (). A constructor is a method that doesn’t return anything (no promise, no generator), it only initialises the instance. And, if not how should a constructor work that does this Such a constructor should not exist at all, see Is it … Read more

How can I export all functions from a file in JS?

No, there’s no wildcard export (except when you’re re-exporting everything from another module, but that’s not what you’re asking about). Simply put export in front of each function declaration you want exported, e.g. export function foo() { // … } export function bar() { // … } …or of course, if you’re using function expressions: … Read more