javascript - Why does a browser need a polyfills file while I compile ES6 to ES5 with babel -


if babel translates es6 es5 , outputs es5 file why browser need include polyfill file if app output file contains es5 code ?

babel translates es6 (and newer) code es5 code. example, rewrites arrow functions (() => {}) es5 functions (function() {}). however, es6 more new syntax.

https://babeljs.io:

since babel transforms syntax (like arrow functions), can use babel-polyfill in order support new globals such promise or new native methods string.padstart (left-pad). uses core-js , regenerator. check out our babel-polyfill docs more info.

all new functions need implemented polyfill. , these polyfills must included globally project. otherwise every usage of es6 function replaced implementation of function in es5 code. if use e.g. array#findindex ten times, transpiled code contain implementation ten times. why polyfills have added globally , not added transpilation step.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -