« get me outta code hell

html: Tag.clone, Template.clone: clone own constructors - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-02 12:36:00 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-08-02 12:36:00 -0300
commit99a56f31caa964081b1a3a1d0749812d804b40cb (patch)
tree10b129f6f444ce67df22ad6a077dab2ec1f01172
parentb4018984c7d3a9b6fd94721ab5df1b4b7124bc0a (diff)
html: Tag.clone, Template.clone: clone own constructors
-rw-r--r--src/util/html.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/util/html.js b/src/util/html.js
index 2468b8d..b49cce0 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -193,7 +193,11 @@ export class Tag {
   }
 
   clone() {
-    return new Tag(this.tagName, this.attributes, this.content);
+    return Reflect.construct(this.constructor, [
+      this.tagName,
+      this.attributes,
+      this.content,
+    ]);
   }
 
   set tagName(value) {
@@ -507,8 +511,12 @@ export class Template {
   }
 
   clone() {
-    const clone = new Template(this.#description);
+    const clone = Reflect.construct(this.constructor, [
+      this.#description,
+    ]);
+
     clone.setSlots(this.#slotValues);
+
     return clone;
   }