I’m trying to document my code with JSDoc (EcmaScript 2015, WebStorm 12 Build 144.3357.8). I have an arrow function which I want to document its parameters. This two examples work (I get auto-completion): But when I want to document an arrow function in forEach function, for example, the auto-completion isn’t working (all of the below): Has anyone managed to get
Tag: ecmascript-6
Allow either named arguments or positional arguments in Javascript
How can I have a function accept either named arguments (foo({a: ‘hello’, b: ‘it is me’})) or positional arguments (foo(‘hello’, ‘it is me’))? I understand that named arguments can be simulated by passing an object to the function: But that does not allow me to accept positional arguments to be passed. I would like to use ES6 but anything from
How to break long import statements into multiple lines in ES6?
I have a pretty long import statement in my JavaScript (ES6) file: Is it OK to add new lines like this? If not, is there any other way to write clean (keeping my code within 80 columns) import statements in ES6 syntax using Babel? Answer Here are the results from my test using ESLint. ESLINT PASSED ESLINT PASSED ESLINT PASSED
es2015 modules – how to name exports dynamically
I would like to create a module, h, which exports one function for every HTML element. Here’s how it might be used: Here’s how that module is defined: I don’t like that every export has to be listed explictly. How do I make these dynamic? Answer how to name exports dynamically You can’t. import and export statements are specifically designed
Can you bind ‘this’ in an arrow function?
I’ve been experimenting with ES6 for a while now, and I’ve just come to a slight problem. I really like using arrow functions, and whenever I can, I use them. However, it would appear that you can’t bind them! Here is the function: Here is the object I want to bind the function to: And here is how I would
TypeScript export vs. default export
What is the difference in TypeScript between export and default export? In all the tutorials, I see people exporting their classes and I cannot compile my code if I don’t add the default keyword before exporting. Also, I couldn’t find any trace of the default export keyword in the official TypeScript documentation. Does not compile. But: Does. The error is:
object destructuring: how to use intermediate nested property
Is there a way to get access to all three in one destructuring call? I want to avoid two calls like so: Answer The closest I can come up with is: Though I’d use let instead, if I’m using ES6 😉
Is there a way to create interfaces in ES6 / Node 4?
ES6 is fully available in Node 4. I was wondering whether it includes a concept of interface to define method contracts as in MyClass implements MyInterface. I can’t find much with my Googling, but maybe there is a nice trick or workaround available. Answer Interfaces are not part of the ES6 but classes are. If you really need them, you
Square Brackets Javascript Object Key
Can anyone explain how the why/how the below method of assigning keys in JavaScript works? return: Answer It’s the new ES2015 (the EcmaScript spec formally known as ES6) computed property name syntax. It’s a shorthand for the someObject[someKey] assignment that you know from ES3/5: is syntactic sugar for:
Why does babel rewrite imported function call to (0, fn)(…)?
Given an input file like babel will compile it to but when compiled in loose mode the function call is output as _b.a(); I’ve done some research into where the comma operator is added in the hope there was a comment explaining it. The code responsible for adding it is here. Answer (0, _b.a)() ensures that the function _b.a is