diff --git a/packages/reactivity/src/collectionHandlers.ts b/packages/reactivity/src/collectionHandlers.ts index 048b7f38863..94c970f236e 100644 --- a/packages/reactivity/src/collectionHandlers.ts +++ b/packages/reactivity/src/collectionHandlers.ts @@ -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 + }, }, - } + ) } }