Skip to content

Instantly share code, notes, and snippets.

@zxhfighter
Last active November 26, 2017 15:56
Show Gist options
  • Save zxhfighter/7428714 to your computer and use it in GitHub Desktop.
Save zxhfighter/7428714 to your computer and use it in GitHub Desktop.
shim vs polyfill

shim和polyfill的区别

前端工程师经常会遇到这两个词:shim和polyfill,这两个是啥东西呢?

shim

英文意思为“垫片”,“垫片”一般是为了填充两个事物的缝隙或者使两件事物结合起来。

在JavaScript的世界里,shim就是一个库,用于将一个新的API引用到一个旧环境中,并且仅仅依靠旧环境中已有的手段实现。

例如IE系列浏览器没有标准的addEventListener方法,但是提供了attachEvent方法,我们可以编写一个方法Element.prototype.addEventListener,内部实现调用attachEvent方法,从而达到统一API的目的。

有时候,shim也被写作shiv,例如html5shiv库。

polyfill

@ganchuhang
Copy link

谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment