Skip to content
Advertisement

Tag: ecmascript-6

ECMAScript 6 class destructor

I know ECMAScript 6 has constructors but is there such a thing as destructors for ECMAScript 6? For example if I register some of my object’s methods as event listeners in the constructor, I want to remove them when my object is deleted. One solution is to have a convention of creating a destructor method for every class that needs

How do you JSON.stringify an ES6 Map?

I’d like to start using ES6 Map instead of JS objects but I’m being held back because I can’t figure out how to JSON.stringify() a Map. My keys are guaranteed to be strings and my values will always be listed. Do I really have to write a wrapper method to serialize? Answer Both JSON.stringify and JSON.parse support a second argument.

Transforming a Javascript iterable into an array

I’m trying to use the new Map object from Javascript EC6, since it’s already supported in the latest Firefox and Chrome versions. But I’m finding it very limited in “functional” programming, because it lacks classic map, filter etc. methods that would work nicely with a [key, value] pair. It has a forEach but that does NOT returns the callback result.

How to feature-detect es6 modules

I’d like to export a module using the ES6 syntax only if it is supported in the current runtime. The goal is to develop a library that support different module management systems. As export is a keyword, something like will throw a syntax error : Answer Use ref

Can I use ES6’s arrow function syntax with generators? (arrow notation)

That is, how do I express with arrow syntax? I’ve tried all the combinations I could think of, and I can’t find any documentation on it. (I am currently using Node.js v0.11.14.) Answer Can I use ES6’s arrow function syntax with generators? You can’t. Sorry. According to MDN The function* statement (function keyword followed by an asterisk) defines a generator

Object destructuring without var, let or const

Why does object destructuring throw an error if there is no var keyword in front of it? throws SyntaxError: expected expression, got ‘=’ The following three examples work without problems Bonus question: Why do we not need a var for array destructuring? I ran into the problem doing something like Answer The issue stems from the {…} operators having multiple

Why couldn’t popular JavaScript runtimes handle synchronous-looking asynchronous script?

As cowboy says down in the comments here, we all want to “write [non-blocking JavaScript] asynchronous code in a style similar to this: ” So people have come up solutions to this problem like callback libraries (eg async) promises event patterns streamline domains and generators. But none of these lead to code as simple and easy to understand as the

Advertisement