Polyfill
What is it and Why it exists
What Is It
Piece of code (usually JavaScript on the Web) used to provide modern functionality on older browsers that do not natively support it.
Why Use It
- Mimic the functionalities of missing features
- address issues where browsers implement the same features in different ways
Implications
Native implementations of APIs can do more and are faster than polyfills
Creating Polyfills
// Assuming we want to use a log API log("this API doesn't exist right now, but will in future") // Above will avaluate to `uncaught ReferenceError: log is not defined` // Patching (creating polyfill) to make API available if (!window.log) { console.log("...patching); // define function on the fly window.log = msg => console.log(msg); }