Community, Javascript

What ES6 features can be used in Node with no transpiler [Part 2]

Let’s continue our investigation on what ES6 features are available today (v4.1.0) in Node.
In part 1 we covered block scoping variables  and Classes, in this post we’ll cover collections.


A good way to start understanding collections in ES6 is reading this great post on from Jason Orendorff.


Here’s a true game changer. Map makes decoupled object-to-object association finally possible in javascript.
As stated in the reference docs “Objects have been used as Maps historically”, but it’s really important we have clear the difference between Map and Object.
While Objects can only map literals to values, with Map can associate value to value.


Let me play the role of Capitan Obvious and say it again: we can now associate objects to objects with no string association example

Other builtin perks are:

  • size  and clear come for free, so we don’t have to keep our own counter as a property (and then to exclude it from the count itself…).
  • NaN uniqueness , even if NaN === NaN is false, we can use NaN as a unique key
  • iterators (entries, values, keys) and a handy forEach method
  • has(key) replacing the quirky hasOwnProperty method to check if a key is present


A Set is a collection of non duplicate values.


The main benefit provided by Set is exactly the main purpose it was designed for: filtering out duplicate objects.
I would bet (too) many times we have found ourselves writing code like the following in order not to add twice the same value to an array…

Screen Shot 2015-10-07 at 19.55.18

… or even to an object…

Screen Shot 2015-10-07 at 19.55.29

And we found out that, unless we put in place a hashing algorithm, or our collection allowed us to use a binary search, we ended up with a linear lookup time that may be not good enough as our collection grows.

Set solves this providing constant lookup time out of the box, and a simple API.

Screen Shot 2015-10-07 at 19.55.37

Check yourself this little benchmark, you will notice the difference as the collection grows. (Run it with: “node <filename> <elements amount> <iterations amount>”).

On top of its main purpose, Set comes with several handy utility methods (similar to Map btw…) such as entries, keys and values (keys and values are the SAME function!!!) iterators, size\clear, has to check if the set contains a given value, and the usual forEach.

WeakMap and WeakSet

I’m grouping these up as we already covered Map and Set individually and these two variants of those data structures are very similar to each other.

WeakMap or WeakSet don’t hold a strong reference to the objects they store, hence if the only existing reference to an object is stored in one of these collections the GC will kill it and free that memory location as it passes.

To get a better understanding of garbage collection in take a look to the examples in the reference docs.


When coming to the benefits these weak collections come with, the typical usecase we will stumble upon is about keeping a reference to a DOM object without impeding the GC from collecting it. Even if that gives us an idea of the functionality, it doesn’t fit well to Node.

An example sitting better in this context could be filtering existing collections without keeping a strong reference to each element of the original collection. Consider the following code:

Screen Shot 2015-10-07 at 22.07.29

What next?

Part 3 will come soon! Watch this space 😉

Community, Javascript

What ES6 features can be used in Node with no transpiler [Part 1]

As soon as I started attending the great London JS community meetups I immediately noticed mixed feelings around ES6.
It seems people is definitely looking forward to it becoming mainstream and they’re hungry for information about it, but at the same time they tend to stand clear of it in production.
Skepticism? Lack of success stories? maybe…
At the time of writing ES6 is not fully supported everywhere and our code needs to be transpiled to older versions of Javascript in order to run properly on all the targets.
Hence, where ES6 is not supported the code we wrote is NOT what gets executed, and all the new cool features provided by ES6 become mere syntactical sugar that comes at a high potential cost:

  • bugs\incompatibilities difficult to debug (as, again, the code we wrote is not the code that is executed)
  • performance issues difficult to overcome (as a new performance enhancement can be transformed in a not-so-performing piece of “old” javascript)

I can imagine some pioneers’ smirk right now. Yes we can run our node app using the ES6 staged features, or even the features currently under development, but is it really a choice? Are we confident enough to run our production app on a beta (or even alpha depending on the maturity of the single feature we plan to toggle) ?

So, let’s consider the bright side for a minute…
Last time I checked the Node docs I read that some ES6 features are ALREADY supported with NO RUNTIME FLAG REQUIRED.
So, I would not go for yet another post on how to fake… ehm…”transpile” ES6 in your Node project, nor I would suggest you to enable all the WIP features.
I’d rather check what is possible to use AS TODAY in Node (version 4.1.0), and identify what are the benefits they come with.

Our trip is going to be long, so let’s start from listing what is available from the menu:

  • Block scoping
    • let
    • const
  • Classes
  • Collections
    • Map
    • WeakMap
    • Set
    • WeakSet
  • Typed arrays
  • Generators
  • Binary and Octal literals
  • Object Literal extensions
  • Promises
  • New String methods
  • Symbols
  • Template strings
  • Arrow functions

Block scoping

let & const

These new features are real game changers (even if you are a “var” aficionado).
While the memory allocated by var lives within the function scope, the memory allocated by let and const lives within the code block.


Syntax sugar aside, a much more granular memory management is VERY welcome.
Before ES6, each time a var was declared a memory location was kidnapped for the entire function scope.
Check the examples in the reference docs, but also consider this example using files and repeat with me: “yes, my app won’t be memory hungry anymore”.
Screen Shot 2015-09-30 at 21.45.47


As the docs reads Classes “are syntactical sugar over JavaScript’s existing prototype-based inheritance. The class syntax is not introducing a new object-oriented inheritance model to JavaScript.”


Syntax sugar, no memory management nor performance benefits.

Where are the others?!

Read Part 2 to get some insight about ES6 collections!

Community, Flash, Javascript, News, Speaking

Speaking at WebTechCon Italy – 9-10 November 2010 – Milano

I’ll be speaking 🙂
The session will be “Flash graphics unleashed”. 30 mins to dig into flash graphics capabilities.
See you there

Some work appointments came through and I’ll not be able to be back for WebTech :
But don’t worry! there’s a HUUUUGE “replacement”, Sandro Ducceschi from SFUG has took over my slots! 🙂
so guys, have fun, I’ll be there with my soul 🙂

Yup, back on stage 🙂

I’ll be speaker at WebTechCon Italy, it’s the first year for this German conference in Italy and there are a HUGE amount of good reasons for you to come.

First of all it’s not all about flash!! There are 5 main tracks: webtech, flash day, silverlight day, javascript day and php4 frontend day… yes, “day” is not to be intended as “whole day” but much more as “track”.

It’s a good opportunity to put an eye on what’s going on on the html5 or silverlight fields and learn something new.

On the flashy side there are a bunch of well known and surely attractive speakers:

Luca Mezzalira ,Andrea Trento ,Marco Casario …I’m sure you all know what those guys are known for… then… well…. there’s me 😀

Further, it’s a good way to meet other guys from TheFlashMind AUG 😉

I’ll be speaking twice on flash graphics and pureMVC.

Be sure you buy a ticket and come, one month’s left, then… rock n roll

Flex, Javascript, Tools

Auto generate getters setters and custom code in Flex builder

Recently I’ve been searching for a plugin for eclipse, a tool, *something*, able to generate code snippets on the fly. This lack of eclipse IDE is filled by a project called Eclipse Monkey, a dead (yes…dead..-.-‘) component of  Project Dash which enables Eclipse to execute javascript functions on demand.

Eclipse Monkey will put a “scripts” menu on your Eclipse menu bar which is populated by the list of scripts (.js) inside the specified folder.

Here’s my Scripts>Actionscript dropdown menu


1) Add project dash site ( )  to your eclipse’s update sites,
2) Restart eclipse,
3) Run create test project by selecting scripts menu,
4) Download actionscript snippets lib from here

…great deal 🙂

Here’s a video showing Eclipse Monkey at work

[flash w=400 h=310 mode=1]


take a look to “Pimp my Eclipse” post from Lee Brimelow (part 1 and 2) for further customizing your eclipse installation 🙂

Javascript, News, Open Source

Wii Remote Javascript SDK

Daniel Gump (gran testa) ha pubblicato sul suo sito web l’sdk per aggiungere ad un sito funzionalit√† fruibili da nintendo wii.

(che bell’oggettino il wii ^^)

Sicuramente è un lavoro dedicato ad una fascia di mercato (e di sviluppatori) ben definita, ma è davvero affascinante.
Non mi dilungo oltre se non indirizzandovi ai link seguenti:

prima o poi anche io sperimenter√≤ il dewiilopment 🙂