feat(reactivity): collection iteration should inherit iterator instance methods

This commit is contained in:
daiwei 2025-01-03 16:25:10 +08:00
parent e8e842241a
commit 9f08043780
1 changed files with 19 additions and 15 deletions

View File

@ -55,7 +55,10 @@ function createIterableMethod(
)
// return a wrapped iterator which returns observed versions of the
// values emitted from the real iterator
return {
return extend(
// inheriting all iterator properties
Object.create(innerIterator),
{
// iterator protocol
next() {
const { value, done } = innerIterator.next()
@ -70,7 +73,8 @@ function createIterableMethod(
[Symbol.iterator]() {
return this
},
}
},
)
}
}