Posts

Showing posts from April, 2015

New number and Math features in ES6

This blog post describes the new number and Math features of ECMAScript 6 . Overview You can now specify integers in binary and octal notation: > 0xFF // ES5: hexadecimal 255 > 0b11 // ES6: binary 3 > 0o10 // ES6: octal 8 The global object Number gained a few new properties. Among others: Number.EPSILON for comparing floating point numbers with a tolerance for rounding errors. A method and constants for determining whether a JavaScript integer is safe (within the signed 53 bit range in which there is no loss of precision). New integer literals ECMAScript 5 already has literals for hexadecimal integers: > 0x9 9 > 0xA 10 > 0x10 16 > 0xFF 255 ECMAScript 6 brings two new kinds of integer literals: Binary literals have the prefix 0b or 0B : > 0b11 3 > 0b100 4 Octal literals have the prefix 0o or 0O (yes, that’s a zero followed by the capital letter O; you’ll be fine if you use the first

Deploying ECMAScript 6

This blog post describes the options you have for deploying ECMAScript 6 in current JavaScript environments. It is selective w.r.t. the amount of tools it covers. If you want a comprehensive list of tools, I suggest you look at Addy Osmani’s “ ECMAScript 6 Tools ”. Consult the blog post “ Using ECMAScript 6 today ” for an overview of ES6 features. Using ECMAScript 6 today What options do you have for using ECMAScript 6 today? ECMAScript 6 features are continually appearing in engines. You can look up which ones are already supported where in Kangax’ “ ECMAScript 6 compatibility table ”. I’d expect first JavaScript engines to fully support ES6 in late 2015 or early 2016. It will take longer until all current engines do so. Especially if you take support for legacy engines into consideration, compiling ES6 to ES5 will be the only viable option for using ES6 for quite a while. Compiling from source code to source code is also called transpiling . You can transpile ES6 either before deploy

Using transpiled ES6 on Node.js

This blog post is outdated (it covers Babel 5). Please read Sect. “ Node.js setup: Statically transpiled ES6 via Babel ” in “Setting up ES6”. This blog post explains how to use ES6 on Node.js by transpiling it to ES5 via Babel. A previous blog post showed how to dynamically transpile ES6 at runtime (also via Babel). That is more convenient and should work for most projects, but occasionally you may want a simpler and faster setup for your runtime environment. Installation Installation consists of downloading the repository node-es6-demo and executing the following commands, which install all npm packages that the repository depends on: $ cd node-es6-demo/ $ npm install The repo has the following structure: node-es6-demo/ es5/ es6/ myapp.js gulpfile.js Source maps Source maps help whenever a language is compiled to JavaScript. Compiling source code to source code is also called transpiling . Examples of transpilation include: Minificati

Writing client-side ES6 with webpack

This blog post is outdated (it covers Babel 5). Please read Sect. “ Browser setup: ES6 via webpack and Babel ” in “Setting up ES6”. webpack is a client-side module builder and module loader. This blog post shows you how to write ECMAScript 6 code with it. The code shown here is on GitHub, in the project webpack-es6-demo . webpack features Notable webpack features include: Supported module formats: AMD, CommonJS Via loader (plug-in): ES6 Supported package managers: Bower, npm Loaders for non-code: CSS, templates, … On-demand loading (chunked transfer) Built-in development server Installing webpack Install webpack: npm install -g webpack Enable support for ECMAScript 6 (via Babel ): Per project: npm install babel-loader --save-dev In your home directory: cd $HOME ; npm install babel-loader Globally: npm install -g babel-loader Using webpack and ES6 in a project The demo project webpack-es6-demo has the following structure: webpack-es6-demo/ es6/ Point.js