mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +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
|
* Gets the next value on a wrapped object following the
|
||||||
* format (<link>). Useful for `for..of` loops and using with
|
* [iterator protocol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterator).
|
||||||
* some ES2015 features.
|
|
||||||
*
|
*
|
||||||
* @name next
|
* @name next
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Chain
|
* @category Chain
|
||||||
* @returns {*} Returns the next value.
|
* @returns {Object} Returns the next iterator value.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var wrapped = _([1, 2]);
|
* var wrapped = _([1, 2]);
|
||||||
@@ -5901,6 +5900,27 @@
|
|||||||
return { 'done': done, 'value': value };
|
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.
|
* Creates a clone of the chained sequence planting `value` as the wrapped value.
|
||||||
*
|
*
|
||||||
@@ -11998,6 +12018,9 @@
|
|||||||
lodash.prototype.toString = wrapperToString;
|
lodash.prototype.toString = wrapperToString;
|
||||||
lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
|
lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
|
||||||
|
|
||||||
|
if (iteratorSymbol) {
|
||||||
|
lodash.prototype[iteratorSymbol] = wrapperToIterator;
|
||||||
|
}
|
||||||
return lodash;
|
return lodash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user