by johnfn · 2y ago · 0 comments
> VM187:1 Uncaught DOMException: Failed to execute 'structuredClone' on 'Window': () => {} could not be cloned.
Ah, yes. I actually asked this question on StackOverflow 5 years ago [0], and the reason it can't be cloned isn't the worst reason ever... but it basically breaks cloning any non-trivial object. Well, I suppose I'll check back in another 10 years when the next ecmascript proposal around cloning lands...
[0]: https://stackoverflow.com/questions/51939812/how-to-clone-an...
https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers...
You have a function, and that function could have local bindings to arbitrary local variables.
> I don't like how short you are, how you phrase this as some huge weakness.
I think you may be reading into my comments more than what is actually there. I think it's a reasonable enough compromise, and I'm happy to have structuredClone.
function f() {
f.count ??= 1;
console.log(f.count++);
}
f(); // Outputs: 1
f(); // Outputs: 2
f(); // Outputs: 3