mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +00:00
Make the chain wrapper iterable.
This commit is contained in:
31
lodash.js
31
lodash.js
@@ -5870,14 +5870,13 @@
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets the next value on a wrapped object in ES2015 iterator
|
||||
* format (<link>). Useful for `for..of` loops and using with
|
||||
* some ES2015 features.
|
||||
* Gets the next value on a wrapped object following the
|
||||
* [iterator protocol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterator).
|
||||
*
|
||||
* @name next
|
||||
* @memberOf _
|
||||
* @category Chain
|
||||
* @returns {*} Returns the next value.
|
||||
* @returns {Object} Returns the next iterator value.
|
||||
* @example
|
||||
*
|
||||
* var wrapped = _([1, 2]);
|
||||
@@ -5901,6 +5900,27 @@
|
||||
return { 'done': done, 'value': value };
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the wrapper to be iterable.
|
||||
*
|
||||
* @name next
|
||||
* @memberOf _
|
||||
* @category Chain
|
||||
* @returns {Object} Returns the wrapper object.
|
||||
* @example
|
||||
*
|
||||
* var wrapped = _([1, 2]);
|
||||
*
|
||||
* wrapped[Symbol.iterator]() === wrapped;
|
||||
* // => true
|
||||
*
|
||||
* Array.from(wrapped);
|
||||
* // => [1, 2]
|
||||
*/
|
||||
function wrapperToIterator() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a clone of the chained sequence planting `value` as the wrapped value.
|
||||
*
|
||||
@@ -11998,6 +12018,9 @@
|
||||
lodash.prototype.toString = wrapperToString;
|
||||
lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
|
||||
|
||||
if (iteratorSymbol) {
|
||||
lodash.prototype[iteratorSymbol] = wrapperToIterator;
|
||||
}
|
||||
return lodash;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user