1. ECMAScript 6 (ES6) New Features:
Arrows are a function shorthand using the
=> syntax. They are syntactically similar to the related feature in Java 8, C# and CoffeeScript. They support both statement block bodies as well as expression bodies which return the value of the expression. Unlike functions, arrows share the same lexical
this as their surrounding code.
ES6 classes are a simple sugar over the prototype-based Object Oriented pattern. Having a single convenient declarative form makes class patterns easier to use, and encourages interoperability. Classes support prototype-based inheritance, super calls, instance and static methods and constructors.
Enhanced Object Literals
Object literals are extended to support setting the prototype at construction, shorthand for
foo: foo assignments, defining methods, making super calls, and computing property names with expressions. Together, these also bring object literals and class declarations closer together, and let object-based design benefit from some of the same conveniences.
Template strings provide syntactic sugar for constructing strings. This is similar to string interpolation features in Perl, Python and more. Optionally, a tag can be added to allow the string construction to be customized, avoiding injection attacks or constructing higher level data structures from string contents.
Destructuring allows binding using pattern matching, with support for matching arrays and objects. Destructuring is fail-soft, similar to standard object lookup
undefined values when not found.
Let + Const
Block-scoped binding constructs.
let is the new
const is single-assignment. Static restrictions prevent use before assignment.
Iterators + For..Of
Iterator objects enable custom iteration like CLR IEnumerable or Java Iterable. Generalize
for..in to custom iterator-based iteration with
for..of. Don’t require realizing an array, enabling lazy design patterns like LINQ.
Iteration is based on these duck-typed interfaces (using TypeScript type syntax for exposition only):
Generators simplify iterator-authoring using
yield. A function declared as function* returns a Generator instance. Generators are subtypes of iterators which include additional
throw. These enable values to flow back into the generator, so
yield is an expression form which returns a value (or throws).
Note: Can also be used to enable ‘await’-like async programming, see also ES7
Non-breaking additions to support full Unicode, including new Unicode literal form in strings and new RegExp
Some additional features include
export default and
Module loaders support:
- Dynamic loading
- State isolation
- Global namespace isolation
- Compilation hooks
- Nested virtualization
The default module loader can be configured, and new loaders can be constructed to evaluate and load code in isolated or constrained contexts.
Map + Set + WeakMap + WeakSet
Efficient data structures for common algorithms. WeakMaps provides leak-free object-key’d side tables.
Proxies enable creation of objects with the full range of behaviors available to host objects. Can be used for interception, object virtualization, logging/profiling, etc.
Symbols enable access control for object state. Symbols allow properties to be keyed by either
string (as in ES5) or
symbol. Symbols are a new primitive type. Optional
description parameter used in debugging – but is not part of identity. Symbols are unique (like gensym), but not private since they are exposed via reflection features like
In ES6, built-ins like
Date and DOM
Elements can be subclassed.
Object construction for a function named
Ctor now uses two-phases (both virtually dispatched):
Ctor[@@create] to allocate the object, installing any special behavior
- Invoke constructor on new instance to initialize
@@create symbol is available via
Symbol.create. Built-ins now expose their
Math + Number + String + Array + Object APIs
Many new library additions, including core Math libraries, Array conversion helpers, String helpers, and Object.assign for copying.
Binary and Octal Literals
Two new numeric literal forms are added for binary (
b) and octal (
Full reflection API exposing the runtime-level meta-operations on objects. This is effectively the inverse of the Proxy API, and allows making calls corresponding to the same meta-operations as the proxy traps. Especially useful for implementing proxies.
Calls in tail-position are guaranteed to not grow the stack unboundedly. Makes recursive algorithms safe in the face of unbounded inputs.
2. Tools are used in Node.js development
Chai is a TDD and BDD assertion framework for Node.js which can be paired with any testing framework (like Mocha.js we just mentioned). We use Mocha.js to run asynchronous testes, but Chai helps us verify the test results. Chai can be run in a browser or with Node.js. As an assertion tool, we use Chai with its rich plugins (ex. chai-as-promised, chai-subset, chai-things). If we need to test Node.js HTTP servers, we usually use SuperTest https://github.com/visionmedia/supertest (it either makes real requests or simulates them while connected to Express.js)
#5 WebStrom IDE
You can do debugging, tracking (with built-in tool spy-js) and unit testing (with easy to integrate Karma or Mocha.js).
Passport.js is an authentication middleware for Node.js. It gives you a choice of over 300 different ways of authenticating your app including username and password model, login via Facebook, Google, Twitter etc., and many other. It’s extremely easy to implement with any Express.js app.
Socket.io is a framework that enables a bi-directional communication in real-time, based on events. It doesn’t matter which device or platform you’re using – it will work great on anything. The package includes real-time analytics with counters, logs and charts. It’s perfect for chat apps and it’s loved by both big companies such as Microsoft, Zendesk, Trello and small startups.
BlueBird.js is a promise library, that helps you to control your asynchronous code. You can separate with it your code into different files without any problem. It’s a must-have if you care about a quality of your code. As an alternative, you can try the Q.
PM2 is a process manager for Node.js applications. It ‘s simple to use and provides many useful built-in features (like load balancer or watch mode).
It’s an universal platform for React.js/Node.js applications. It’s brought by WalmartLabs which means that this set of tools had been tested on a huge amount of data. It’s not only a set of best practices, standardized structure and modern technologies – it also includes Electrode Explorer and Electrify. These tools let you explore all docs and components of your platform as well as visualize in a clear and appealing way the module tree of electrode.io + Webpack project bundles.
While Meteor.js is great for prototyping apps, it’s good to keep in mind that it might not be the best solution for maintaining the already finished ones.
A great alternative for those who use Angular.js is Vue.js . If you don’t want to build a complex web app and have to configure routings, controllers and services then Vue.js could be the lightweight solution you’re looking for. This framework is focused on a ViewModel – you get features of larger frameworks in a lighter version for your single page applications.
Donate $5 to me for a coffee with PayPal
and read more professional and interesting technical blog articles. Feel free to visit my web app, WhizWallet
, to apply for credit, store or gift cards, DealsPlus
to browse daily deals and store coupons to save money.
Follow me @Yaoli0615
at Twitter to get latest tech updates.
Node.js Design Patterns
Web Development with MongoDB and NodeJS