Use ponyfill.com for linking here.
A ponyfill is an implementation of a standard, but without pretending to be it.
Unlike polyfills, ponyfills don't pretend to be the native API. They offer the same functionality through explicit imports and usage, keeping your code predictable and side-effect free.
The problem with polyfillsIn JavaScript, a polyfill adds missing features by monkey patching the environment, typically by modifying globals like Array.prototype
, Object
, or window
. This approach creates several problems:
In general, you should not modify APIs you don’t own. Ponyfills avoid this entirely by staying pure.
It’s not just for JavaScriptPonyfills are clear. Explicit. Honest. You use them directly and deliberately.
Number.isNaN ??= function (value) { return value !== value; };
import 'is-nan-polyfill'; Number.isNaN(5);
export default function isNaN(value) { return value !== value; };
import isNanPonyfill from 'is-nan-ponyfill'; isNanPonyfill(5);
<!-- Instead of a future <card> element --> <card-ponyfill> <h2 slot="title">Hello</h2> </card-ponyfill> <script> customElements.define('card-ponyfill', class extends HTMLElement { connectedCallback() { this.innerHTML = `<div class="card">${this.innerHTML}</div>`; } }); </script>
/* Instead of future syntax like @container */ :root { --container-sm: 480px; --container-lg: 768px; } .responsive-text[data-container='small'] { font-size: 0.875rem; } .responsive-text[data-container='large'] { font-size: 1.125rem; }
<div class="responsive-text" data-container="small">Responsive text</div>Why not use the native API in a ponyfill when available?
Ponyfills should avoid relying on native APIs unless unavoidable because:
Use native APIs only when:
ponyfill
to the keywords fieldTo the extent possible under law, Sindre Sorhus has waived all copyright and related or neighboring rights to this work.
Header based on work by Mary Winkler.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4