LEARNING JAVASCRIPT - Trang 40

1

Some JavaScript engines (Node, for example) do compile your JavaScript, but it happens transparently.

but it is going to put an extra burden on the programmer, as ES6 code has to be trans‐

compiled into “safe” ES5 to ensure that it can run anywhere.
Programmers who have been around a while might be thinking “big deal; back in my

day, there was no such thing as a language that didn’t have to be compiled and

linked!” I’ve been writing software long enough to remember that time, but I do not

miss it: I enjoy the lack of fuss in interpreted languages like JavaScript.

1

One of the advantages of JavaScript has always been its ubiquity: it became the stan‐

dard browser scripting language almost overnight, and with the advent of Node, its

use broadened beyond the browser. So it is a bit painful to recognize that it will prob‐

ably be a few years before you can ship ES6 code without worrying about browsers

that don’t support it. If you’re a Node developer, the situation is a little bit brighter:

because you only have one JavaScript engine to worry about, you can track the pro‐

gress of ES6 support in Node.

The ES6 examples in this book can be run in Firefox, or on a web‐

site such as

ES6 Fiddle

. For “real-world code,” however, you will

want to know the tools and techniques in this chapter.

One interesting aspect about JavaScript’s transition from ES5 to ES6 is that, unlike

language releases of the past, the adoption is gradual. That is, the browser you’re using

right now probably has some—but not all—features available in ES6. This gradual

transition is made possible in part by the dynamic nature of JavaScript, and in part by

the changing nature of browser updates. You may have heard the term evergreen used

to describe browsers: browser manufacturers are moving away from the concept of

having discrete browser versions that have to be updated. Browsers, they reason,

should be able to keep themselves up to date because they are always connected to the

Internet (at least if they are going to be useful). Browsers still have versions, but it is

now more reasonable to assume that your users have the latest version—because

evergreen browsers don’t give users the option not to upgrade.
Even with evergreen browsers, however, it will be a while before you can rely on all of

the great features of ES6 being available on the client side. So for the time being,

transcompilation (also called transpilation) is a fact of life.

ES6 Features

There are a lot of new features in ES6—so many that even the transcompilers we’ll be

talking about don’t currently support all of them. To help control the chaos, New

16 | Chapter 2: JavaScript Development Tools

Liên Kết Chia Sẽ

** Đây là liên kết chia sẻ bới cộng đồng người dùng, chúng tôi không chịu trách nhiệm gì về nội dung của các thông tin này. Nếu có liên kết nào không phù hợp xin hãy báo cho admin.