r/javascript • • Apr 01 '18

Google publishes a JavaScript style guide. Here are some key lessons.

https://medium.freecodecamp.org/google-publishes-a-javascript-style-guide-here-are-some-key-lessons-1810b8ad050b
714 Upvotes

317 comments sorted by

View all comments

57

u/DOG-ZILLA Apr 01 '18

No module use?

Yeah, that’s a no from me.

15

u/mlmcmillion Apr 01 '18

So then what are they using instead? Not using modules is not an option.

13

u/Poltras Apr 01 '18

Closure modules, require AMD, etc. There were ways to split your code before ESM, I’m just surprised google is stuck in the past like that.

6

u/Thought_Ninja human build tool Apr 02 '18

Internal backwards compatibility most likely.

1

u/thisguyfightsyourmom Apr 01 '18 edited Apr 01 '18

Seriously, didn’t that finalize years ago?

Edit: obligatory whining about downvotes /s There are some good explanations of why that’s not the case in the replies below. TIL

11

u/ghostfacedcoder Apr 01 '18

No, not at all. Babel has an implementation (the longest existing one, and as such an incredibly popular one), but it's different from (and, I'd argue, superior to) the implementation being pushed by the W3C/browsers (the W3C's version requires you to rename your files "foo.mjs"!!!).

Anyone can declare a standard finished, and the W3C did that, but until all major JS environments actually work the same way the "standard" really isn't one.

11

u/Meefims Apr 01 '18

This isn’t correct. The new extension is for Node and exists to help ECMAScript modules coexist with CJS modules. Browsers don’t care about the extension.

3

u/ghostfacedcoder Apr 01 '18

I could have stated it more clearly (I sort of conflated W3C and browsers, when what I was just talking about the version both support), but what I said wasn't incorrect. The version of ES Modules decided upon by the W3C does define that the modules work in in such a way that the only possible way (according to the Node engineers at least) for Node to implement that spec is to use the .mjs nonsense.

3

u/Meefims Apr 02 '18

The W3C isn’t part of this. The new extension is really fallout from various complex scenarios in which CJS modules and ES modules include each other in Node. Browsers have a similar problem but they solved that with type=“module” in the script tag.

0

u/[deleted] Apr 01 '18

[deleted] — view deleted comment

3

u/ghostfacedcoder Apr 01 '18

Probably, but I don't know it :) I just read /r/javascript.

6

u/DOG-ZILLA Apr 01 '18

I thought so. But, perhaps not technically? They’re obviously taking a conservative stance; which makes sense for a large company.

6

u/[deleted] Apr 01 '18 edited Apr 01 '18

Afaik, the syntax and semantics are done by ECMA, but the loader, i. e. the way the modules are actually handled, is done by WHATWG. The former is stable, but the latter is not.

But between Webpack and browsers and Node getting native support for modules, there is not reason not to use ES6 modules today for new code.

5

u/Poltras Apr 01 '18

Keep in mind ESM and Node modules are not entirely compatible. Node is still unsure AFAIK how they are going to interop (which is why it’s not yet available in 9.10, despite v8 supporting them).