MDN says that "Function objects cannot be duplicated by the structured clone algorithm; attempting to throws a DataCloneError exception."
Why does copying a function object emit an error with structuredClone()?
MDN says that "Function objects cannot be duplicated by the structured clone algorithm; attempting to throws a DataCloneError exception."
Why does copying a function object emit an error with structuredClone()?
If you read on MDN/structuredClone, it says
Exceptions
DataCloneErrorDOMException
- Thrown if any part of the input value is not serializable.
For why functions are not serializable, see here: Why is a function not serializable?
From what I understand of those answers, the TL;DR is that it's because a function can be converted to a string, but the variables/functions referenced in the function that are out of scope would cause issues.