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.
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
Post a Comment