mirror of https://github.com/vuejs/core.git
feat(reactivity): collection iteration should inherit iterator instance methods
This commit is contained in:
parent
e8e842241a
commit
9f08043780
|
@ -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,
|
||||
}
|
||||
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
|
||||
},
|
||||
},
|
||||
// iterable protocol
|
||||
[Symbol.iterator]() {
|
||||
return this
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue