best way to convert ES6 syntax to ES5 ?
best way to convert ES6 syntax to ES5 ?
型号:
价格:
颜色:
浏览:38
数量:
 
Oooo, this thread could get flamey! Ha ha. There are numerous advantages to using ES6, a qu

Oooo, this thread could get flamey! Ha ha.

There are numerous advantages to using ES6, a quick google search will give you heaps of reasons, with the only con being that you probably have to up the complexity to transpile back to es5/3, however, all modern browsers support most of ES6 (and newer) syntax so unless you're supporting really old browsers (and you stick solely to ES6) then you probably don't need to transpile.

The biggest advantages of ES6 (for me, and I've missed loads here):

* ES6 was pushed through to create more complex applications, as such it has a lot of syntax that is more useful for doing so. Some are sugar methods only, some actually provide newer functionality (particularly those related to primitives and/or the DOM).

* New built-in extensions which make many tasks way way easier (and easier means less error-prone)

* Sugar methods mean less dev typing which generally means less mistakes. Some things ES6 makes easy are very very hard in ES5 and they are often things devs rely on regularly so making them easier to work with means writing code is less error-prone and reading code is clearer so you can focus on what your code does, not how it does it.

The biggest advantages of setting up a transpilation pipeline are (again, I'm missing loads):

* Access to a module system

* Access to whatever new syntax you want

The con of a transpilation system is increased project complexity and you have introduced a build step which takes some time to run, as your project grows this sometimes becomes prohibitive but you do have to have a very large project for this to happen and most modern build tools abstract away incremental builds and caching i.e. they only re-build the changes so incremental builds become smaller and faster.

Another con is related to the module system. Modules are awesome, very awesome. However, JS doesn't (yet) natively support them in the browser and even when they do there are additional problems i.e. if you use modules heavily (as you probably should) then your list of dependencies could easily be hundreds or even thousands of files, loading each of these one by one in the browser isn't a good idea and won't be in the foreseeable future.

A module system also implies that you need some way of getting dependencies. This isn't technically necessary but is often helpful. If you are writing games then often you'll be using one (or maybe two) large frameworks to help, unless they work nicely with a dependency management system (i.e. NPM) then I wouldn't worry about getting them as 'real' modules, just include them on the page and use them, then use a module system for your own code if you want to.

Newer syntax and mobile games

Any gaming is typical performance sensitive, newer syntax has a few things to consider:

* Browsers are well optimised for ES5, this isn't always true to ES6 (although ES6 is pretty good now as its fairly old and almost universally adopted in browsers)

* Given the above, transpiling is often better for performance

* The code generated by these tools during transpilation is superb, it is written by many many superb developers and has great community support so the hours invested in it must be astronomical i.e. in many cases these tools will write better code than you or I do!

* It is not a silver bullet -> if perf is a concern for you then you are still largely the sole arbiter of whether you achieve your perf goals.

How to use newer language features:

Babel is the defacto tool (although it isn't your only option). Babel requires a bit of setup work and additionally requires you to set up a build process for your code. Again, there is tooling for this. Additionally, there are many project scaffolds out there (and tools for creating them) that can abstract this away.

The absolute easiest way of getting access to these new language features but supporting older browsers is to use parceljs.

Parcel abstracts away most of the complicated build stuff and has a superb feature set. It involves a few pre-requisites:

* You must know how to run simple commands from the command line

* You must have Node and NPM installed

Once you have these things (which is generally true of any JS build system you might want to employ) then running builds is a simple one-line command. A watch task is also bundled in, this is another simple one-line command to run and watches the file system, every time you save a change it rebuilds only what has changed and propagates that to the browser. Parcel relies heavily on caching and multi-threading so is very very fast.

Other tools include webpack (which is very complicated, although newer versions I think make things way way easier for most use-cases) and browserify (which is simpler in scope, but can feel a little low-level for many people).

以下是网友对 best way to convert ES6 syntax to ES5 ? 的评论:
发表评论
大名:

版权所有 © a片免费成人毛片免费观看-国产一级片 蜀ICP备123456

这时外面响起来叫门声:”有没有人啊?开门啊!a片免费成人毛片免费观看-国产一级片”白洁一听低声的告诉高义:”是楼上的。”两人才放下心来。高义把慢慢的抽动着,白洁轻轻的扭动着屁股。 叫了几声门,那人嘴里嘟囔着走了,“快a片免费成人毛片免费观看-国产一级片点吧……他快回来了……”白洁喘息着说。高义开始不停地快速抽送,两人交合摩擦的水声“叭叽、叭叽”的响着,“嗯……哼……哦……”白洁轻声的叫着。 很快,高义一泄如注,白洁跪在沙发上喘息了一会儿,a片免费成人毛片免费观看-国产一级片起来刚要穿内裤,便听见门口响起熟悉的脚步声,王申回来了。情急之下,白洁把内裤a片免费成人毛片免费观看-国产一级片塞到了沙发后面,整理了一下衣服,正襟危坐在那里。 高义一看四周也没有人,一下抱起白洁,钻进了旁边一个茂密的小树林…… 茂密的灌木里面有着一片小小a片免费成人毛片免费观看-国产一级片的空地,有意思的是还铺着两张报纸,可惜已经破烂不堪了,在角落的地方竟然还有一个用过的避孕套,里面还有着干涸的。 进了这里,高义的手就已经在白洁的a片免费成人毛片免费观看-国产一级片胸脯上乱摸了,白洁微微喘着气:“别摸脏了,别……”高义就解开她的衬衫扣子,把一对肉鼓鼓的从乳罩上边掏了出来。高义的手很大,但刚好是握住还握不住的感觉,黄豆粒一样大的粉a片免费成人毛片免费观看-国产一级片嫩粉嫩的正在慢慢变硬,秀美的眼睛微微闭着,长长的睫毛在不停地抖动。 高义的手在往上卷着白洁的裙子,可是牛仔裙a片免费成人毛片免费观看-国产一级片很紧,卷不上来,白洁推开高义,手伸到裙子后面,原来后面有一个拉链。拉开拉链,高义把白洁的裙子拉到了脚下,白洁里面是一条水绿色的小内裤,除了三角区之外都是镂空的。高义的a片免费成人毛片免费观看-国产一级片手抚摸着两瓣露出的雪白屁股,让白洁弯下腰,手扶着前面的一个树杈,他解开了裤子……