Better to export an object containing function, or just export multiple functions in ES6 (Is there a convention?)

Going forward, it’s probably better to export multiple functions, as tree shaking allows module bundlers to eliminate dead code based on whether it’s been imported or not. If you export one large object, it’s not always possible to use static analysis to tell which functions need to be kept and which can be safely discarded. … Read more

Get parent class name from child with ES6?

ES6 classes inherit from each other. So when instance.constructor refers to the Child, then you can use Object.getPrototypeOf(instance.constructor) to get the Parent, and then access .name: Object.getPrototypeOf(instance.constructor).name // == “Parent” Of course, full ES6 compliance and non-minified code are necessary for this to work. You should never rely on function names in code.

destructuring assignment default value [duplicate]

You probably confused by the difference between null and undefined, For example: const { dogName=”snickers” } = { dogName: undefined } console.log(dogName) // what will it be? ‘snickers’! const { dogName=”snickers” } = { dogName: null } console.log(dogName) // what will it be? null! const { dogName=”snickers” } = { dogName: false } console.log(dogName) // … Read more

what does super() do without any arguments?

In ES6, derived classes have to call super() if they have a constructor. In react, all components extend from the Component class. You don’t actually need a constructor for every ES6/react class. If no custom constructor is defined, it will use the default constructor. For base classes, it is: constructor() {} And for derived classes, … Read more

Cannot import exported interface – export not found

The root cause is in Typescript and transpilation. Once TypeScript code is transpiled, interfaces/types are gone. They don’t exist anymore in the emitted files. While the types are erased, the imports/exports aren’t necessarily. The reason is that there are ambiguities and that the compiler doesn’t always know for sure whether something that is exported is … Read more

How to replace /n to linebreaks in react.js?

An alternative to this would be to use css to display it with line breaks. This also makes it easier to copy and paste with the original line breaks as well as distinguishing between one break (\n) and two breaks (\n\n). Just add the style white-space: pre-wrap; to your element. <div style={{whiteSpace: “pre-wrap”}}>{note.note}</div> There are … Read more

Override a setter, and the getter must also be overridden

Yes, this is intentional (a part of the spec). If an object has an own property (.property in your example), this property will be used and not an inherited one. If that property is existent, but is an accessor property without a getter, then undefined will be returned. Notice that this behaviour has not changed … Read more