Back to TIL
April 2025
posted on 04.10.2025

Copy a function in JavaScript

const newFunction = oldFunction.bind({});
  • Function.prototype.bind() creates a new function with this set to the value passed in the argument.
  • A new function is created and it references the function that bind was called on.
  • The new function will not have references to any additional properties that may have been attached to the original function.
No reactions yet

2026.10.01 14:01:34 in Naperville, IL
Last visitor from Mitaka, Japan
Theme
Color theme
⌘K