Jan 22 2014

Symbols in nodejs

Symbols in nodejs

Symbols are a new feature in ES6 that allows us to set true private properties on object, without fear of name conflicts. The cool thing is, you can kind of do it already in ES5, and the symbol module offers it for nodejs.

var Symbol = require('symbol');
var key = new Symbol;
var obj = {};
obj[key] = "foo"; // no one can access without a reference to `key`
  • #javascript
  • #programming
  • #nodejs
  • #symbol
  • #es6
  • #planet