Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

javascript - polyfill和transpiler有什么区别?(What is the difference between polyfill and transpiler?)

What is the difference between a polyfill and transpiler?

(polyfill和transpiler有什么区别?)

I often read the same term used in similar context.

(我经常阅读在类似情况下使用的相同术语。)

  ask by Rohit Sharma translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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功能,例如粗箭头功能 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...