Skip to content

Instantly share code, notes, and snippets.

@ryanmorr
Last active March 29, 2024 06:40
Show Gist options
  • Save ryanmorr/98fee9895080298c32b9d18cd9fe1ee1 to your computer and use it in GitHub Desktop.
Save ryanmorr/98fee9895080298c32b9d18cd9fe1ee1 to your computer and use it in GitHub Desktop.
Port a method to be used standalone
function port(fn) {
return Function.prototype.bind.call(Function.call, fn);
}
// Usage:
// port the `forEach` method of the Array prototype
const each = port([].forEach);
// Use standalone by passing the contextual object as the first argument
each(document.querySelectorAll('div'), (el) => console.log(el));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment