Both approaches serve the same purpose: You can write code, that uses some features, which are not yet implemented in your target environment.
(两种方法具有相同的目的:可以编写使用某些功能的代码,而这些功能尚未在目标环境中实现。)
They do this, however, by using different techniques.(但是,他们通过使用不同的技术来做到这一点。)
A polyfill will try to emulate certain APIs, so can use them as if they were already implemented.
(polyfill将尝试模拟某些API,因此可以像已实现它们一样使用它们。)
A transpiler on the other hand will transform your code and replace the respective code section by other code, which can already be executed.
(在另一方面,一个transpiler将改变你的代码和其它代码,这已经可以执行替换相应的代码段。)
Typically you use a polyfill, if your target browser did not yet implement the latest bleeding edge feature (read browser APIs) you want to use.
(如果目标浏览器尚未实现您要使用的最新功能(读取浏览器API),则通常使用polyfill。)
A transpiler on the other hand will let you use language features, the target environment does not support yet, eg some ES6 features like fat arrow functions .(另一方面,编译器将允许您使用语言功能,但目标环境尚不支持,例如某些ES6功能,例如粗箭头功能 。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…