AngularJS 2.0 rewritten in ECMAScript?

2.5k Views Asked by At

So I just found out today that Angular 2.0 is coming out, they are using ECMAScript 6, but compiling it to 5, etc., etc., etc.

How will that (using ECMAScript) affect the usage? How will it be compatible with the JavaScript I use to call its API? I mean, having different languages (ES, JS) written together?

Confused at how this works. Help is appreciated.

EDIT

Sorry @Joseph if my question wasn't clear enough, but I also (mainly) want to know how ECMAScript 5 runs in the browser and the second paragraph above keeping this in context.

How does a JavaScript person use Angular 2.0? How does ES work alongside JS code?

From the docs:

Though Angular will be in ES6, you can still write in ES5 if you don’t want to upgrade. The compiler generates readable JS and there are human-sensible analogs for the extensions.

I suspect that ES can be run by JS interpreters(?)

1

There are 1 best solutions below

1
On BEST ANSWER

AngularJS 2.0 rewritten in ECMAScript?

Seems like you've mistaken ES for another language.

ES (ECMAScript) is a standard which JavaScript language is based on. It defines the rules and behaviors of JS and other languages based on it. ES5 is the 5th revision, ES6 is the upcoming revision at the time of writing.

they are using ECMAScript 6, but compiling it to 5

Pretty much every browser today is ES5 compatible while not so with ES6. There are incentives to using ES6 like the new API and very convenient syntax - but these aren't present in ES5. In order for one to be able to use ES6 right now but still, one needs the ES6 code transpiled to ES5.

This means Angular is written in ES6 syntax, but the code is transpiled (converted) back to an ES5 equivalent to enable present browsers to run it.

Here's an example of code doing the same thing, one written in ES6, and the other in ES5 generated from a transpiler. Notice the convenience of the ES6 version compared to how one would have done it in ES5.

// ES6
var seattlers = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }];

// ES5
var seattlers = customers.filter(function (c) {
  return c.city == "Seattle";
}).map(function (c) {
  return {
    name: c.name,
    age: c.age
  };
});

How will that affect the usage?

How will it be compatible with the JavaScript I use to call its API?

having different languages written together

They (Angular) wrote it in the upcoming version, then convert it back to the current version which can run on present-day browsers. No extra effort on the consumer part. This move was probably to make the code "forward-looking", preparing the codebase for the future version today.