How do I perform an export that is compatible with ES5 and ES6?

As far as writing an export that is compatible for both ES5 and ES6, Babel already takes care of that for you. (As communicated in the comments to your question. I’m only clarifying for those who got lost in the dialog.) module.exports = MyClass will work with both var MyClass = require(‘mymodule’) and import MyClass … Read more

‘Access-Control-Allow-Credentials’ header in the response is ” which must be ‘true’

While setting cors in corsOptions I added value credentials true it worked as follows: private setCors(){ let whitelist = [‘http://localhost:4200′,’http://localhost:80’]; let corsOptions = { origin: (origin:any, callback:any)=>{ if (whitelist.indexOf(origin) !== -1) { callback(null, true) } else { callback(new Error(‘Not allowed by CORS’)) } },credentials: true } this.app.use(cors(corsOptions)); }

ES6: “import * as alias” vs “import alias”

From your example: Case A: //utils.js export function doSomething() { //… } Case B: //utils.js export function doSomething() { //… } export default function doSomethingDefault() { //… } Result: import utils from ‘utils’ utils() // (Case A: undefined, Case B: doSomethingDefault) import * as utils from ‘utils’ utils // (Case A: utils = { doSomething: … Read more

Why is `throw` invalid in an ES6 arrow function?

If you don’t use a block ({}) as body of an arrow function, the body must be an expression: ArrowFunction: ArrowParameters[no LineTerminator here] => ConciseBody ConciseBody: [lookahead ≠ { ] AssignmentExpression { FunctionBody } But throw is a statement, not an expression. In theory () => throw x; is equivalent to () => { return … Read more

Delegated yield (yield star, yield *) in generator functions

Delegating to another generator means the current generator stops producing values by itself, instead yielding the values produced by another generator until it exhausts it. It then resumes producing its own values, if any. For instance, if secondGenerator() produces numbers from 10 to 15, and firstGenerator() produces numbers from 1 to 5 but delegates to … Read more

What is “new.target”?

You didn’t find it in the spec because in the syntax definitions it is written with blanks, as new . target. The name of the expression is NewTarget, and you’ll find that term a few times around. NewTarget is the first of the so-called meta properties and can be found in §12.3.8. Its sole purpose … Read more

How do I override inherited methods when using JavaScript ES6/ES2015 subclassing

The solution I found was to create a new function in the subclass that has the same name as the inherited function. In this case push. Then inside the overriding function the inherited function is called via the super keyword. class newArray extends Array{ push(value) { //execute any logic require before pushing value onto array … Read more

“Unterminated template literal” syntax error when literal contains script tag [duplicate]

If you insert </script> inside a script tag, no matter if it’s a string in quotes, apostrophes, or even a template literal, it will always close the script tag. You have to escape it, for example like that: var str=` <script> <\/script> ` var pre = document.createElement(‘pre’) pre.textContent = str document.body.appendChild(pre) However, if you use … Read more