ES6 in node.js

Well first for thanks to paulmillr for his wonderful contribution of es6-shim for node.js and browsers.

As ECMAScript 6 drafts gets better each day, /me had an itch to try it before the browser wars will implement them on after the other, this itch led me to try it with node.js and trust me it's awesome!

Well as of today, FF13 is the first browser to introduce Sets and Maps API but we can try out the features in node.js right away.

If you still don't have node.js do install it $ bash < <(curl h3manth.com/njs) then install es6-shim with npm just do $ npm install es6-shim

Rock and Roll baby!:

> require('es6-shim')
{}
 
> 'hemanth.hm'.startsWith('h')
true
 
> 'hemanth.hm'.endsWith('hm')
true
 
> '*'.repeat(10)
'**********'
 
> 'node rocks'.contains('node')
true
 
> Array.from("hemanth is testing ES6")
[ 'h',
  'e',
  'm',
  'a',
  'n',
  't',
  'h',
  ' ',
  'i',
  's',
  ' ',
  't',
  'e',
  's',
  't',
  'i',
  'n',
  'g',
  ' ',
  'E',
  'S',
  '6' ]
 
> Array.of("hemanth is testing ES6")
[ 'hemanth is testing ES6' ]
 
> 'node rocks'.toArray()
[ 'n',
  'o',
  'd',
  'e',
  ' ',
  'r',
  'o',
  'c',
  'k',
  's' ]
 
 
> Number.isNaN('1337')
false
 
> Number.toInteger('1337.7')
1337
 
> Number.isInteger('1337.7')
false
 
> Number.isFinite('1337.7')
false
 
> Number.isFinite(1337.7)
true
 
> Math.sign(-0) //What?!
0
 
> Math.sign(-5)
-1
 
> Math.sign(5)
1

When all the browsers implement them, it will be very easy to play with DOM elements for sure! Happy Hacking

Update 0 : After noticing Math.sign(-0)

> Object.is(Math.sign(-0),-0)
true
 
> Object.is(Math.sign(-0),0)
false

-0 is an IEEE754 binary double precision value, just as +0 is. It has negative sign. ECMA-262 covers IEEE754 in 8.5 "The Number Type"

Share this