whatwg / dom

DOM Standard
https://dom.spec.whatwg.org/
Other
1.56k stars 290 forks source link

Provide a "deep clone" shorthand #1220

Open marcoscaceres opened 1 year ago

marcoscaceres commented 1 year ago

The "with the clone children flag set to true" is kinda clunky in prose... it would be amazing to have "deeply clone" shorthand that does the same thing.

For example, instead of:

Let clone be a clone of someElementOrFragment, with the clone children flag set to true.

Nicer:

Let clone be a deep clone of someElementOrFragment.

annevk commented 1 year ago

Looking at https://dontcallmedom.github.io/webdex/c.html#clone%20a%20node%40%40dom%25%25dfn that doesn't really seem worth it. Perhaps once there are more callers?

We should modernize the algorithm though as per https://infra.spec.whatwg.org/#algorithm-params. Probably the document argument should be an optional named argument and s/clone children flag/deep/ can just be an optional boolean. It's kinda annoying that for consistency it would have to default to false. Perhaps we could consider flipping that, but not sure it's worth it.