Câu hỏi phỏng vấn Javascript
Câu hỏi

What is the difference between a shim and a polyfill?

Câu trả lời

The difference between a shim and a polyfill in JavaScript revolves around their purpose and implementation in web development.

Shim

A shim is a piece of code that intercepts API calls and modifies or adds new behaviors to existing APIs to correct issues or add new functionalities. Shims are primarily used to fix or enhance the behavior of older browsers that support the API but have bugs or inconsistencies in their implementation. For example, a shim might intercept calls to an existing API and provide a consistent behavior across different browsers, effectively smoothing out discrepancies without introducing new APIs[1][4][5].

Polyfill

A polyfill, on the other hand, is a type of shim that specifically targets the implementation of new APIs that are not supported by older browsers. It allows developers to use modern web standards by emulating the missing APIs in older environments. If a browser does not support a particular API, the polyfill checks for its presence and implements it if it's missing. This enables developers to write modern code without having to worry about browser compatibility issues. Polyfills are often more complex than shims because they may involve emulating entire APIs that do not exist in some browsers[1][2][3][4][5].

Key Differences

  • Purpose: Shims are used for correcting ex...
middle

middle

Gợi ý câu hỏi phỏng vấn

middle

What are the differences between ES6 class and ES5 function constructors?

middle

When should we use generators in ES6?

junior

What is a Polyfill?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào