]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(reactivity): collection iteration should inherit iterator instance methods edison/fix/12615 12644/head
authordaiwei <daiwei521@126.com>
Fri, 3 Jan 2025 08:25:10 +0000 (16:25 +0800)
committerdaiwei <daiwei521@126.com>
Fri, 3 Jan 2025 08:25:10 +0000 (16:25 +0800)
packages/reactivity/src/collectionHandlers.ts

index 048b7f38863740f0592d6dd566c0c2f6d3250885..94c970f236e34dea71e324878b64d73f06df77d8 100644 (file)
@@ -55,22 +55,26 @@ function createIterableMethod(
       )
     // return a wrapped iterator which returns observed versions of the
     // values emitted from the real iterator
-    return {
-      // iterator protocol
-      next() {
-        const { value, done } = innerIterator.next()
-        return done
-          ? { value, done }
-          : {
-              value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
-              done,
-            }
-      },
-      // iterable protocol
-      [Symbol.iterator]() {
-        return this
+    return extend(
+      // inheriting all iterator properties
+      Object.create(innerIterator),
+      {
+        // iterator protocol
+        next() {
+          const { value, done } = innerIterator.next()
+          return done
+            ? { value, done }
+            : {
+                value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
+                done,
+              }
+        },
+        // iterable protocol
+        [Symbol.iterator]() {
+          return this
+        },
       },
-    }
+    )
   }
 }