Make doc code sample comments match source comment style. [ci skip]

This commit is contained in:
John-David Dalton
2016-01-29 22:41:02 -08:00
parent 13659e87cb
commit 1f160b31ff

189
lodash.js
View File

@@ -1254,14 +1254,14 @@
* lodash.isFunction(lodash.bar); * lodash.isFunction(lodash.bar);
* // => true * // => true
* *
* // using `context` to mock `Date#getTime` use in `_.now` * // Use `context` to mock `Date#getTime` use in `_.now`.
* var mock = _.runInContext({ * var mock = _.runInContext({
* 'Date': function() { * 'Date': function() {
* return { 'getTime': getTimeMock }; * return { 'getTime': getTimeMock };
* } * }
* }); * });
* *
* // or creating a suped-up `defer` in Node.js * // Create a suped-up `defer` in Node.js.
* var defer = _.runInContext({ 'setTimeout': setImmediate }).defer; * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
*/ */
function runInContext(context) { function runInContext(context) {
@@ -1451,11 +1451,11 @@
* *
* var wrapped = _([1, 2, 3]); * var wrapped = _([1, 2, 3]);
* *
* // returns an unwrapped value * // Returns an unwrapped value.
* wrapped.reduce(_.add); * wrapped.reduce(_.add);
* // => 6 * // => 6
* *
* // returns a wrapped value * // Returns a wrapped value.
* var squares = wrapped.map(square); * var squares = wrapped.map(square);
* *
* _.isArray(squares); * _.isArray(squares);
@@ -5471,7 +5471,7 @@
* _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor); * _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
* // => [3.1, 1.3] * // => [3.1, 1.3]
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
* // => [{ 'x': 2 }] * // => [{ 'x': 2 }]
*/ */
@@ -5603,15 +5603,15 @@
* _.dropRightWhile(users, function(o) { return !o.active; }); * _.dropRightWhile(users, function(o) { return !o.active; });
* // => objects for ['barney'] * // => objects for ['barney']
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.dropRightWhile(users, { 'user': 'pebbles', 'active': false }); * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
* // => objects for ['barney', 'fred'] * // => objects for ['barney', 'fred']
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.dropRightWhile(users, ['active', false]); * _.dropRightWhile(users, ['active', false]);
* // => objects for ['barney'] * // => objects for ['barney']
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.dropRightWhile(users, 'active'); * _.dropRightWhile(users, 'active');
* // => objects for ['barney', 'fred', 'pebbles'] * // => objects for ['barney', 'fred', 'pebbles']
*/ */
@@ -5643,15 +5643,15 @@
* _.dropWhile(users, function(o) { return !o.active; }); * _.dropWhile(users, function(o) { return !o.active; });
* // => objects for ['pebbles'] * // => objects for ['pebbles']
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.dropWhile(users, { 'user': 'barney', 'active': false }); * _.dropWhile(users, { 'user': 'barney', 'active': false });
* // => objects for ['fred', 'pebbles'] * // => objects for ['fred', 'pebbles']
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.dropWhile(users, ['active', false]); * _.dropWhile(users, ['active', false]);
* // => objects for ['pebbles'] * // => objects for ['pebbles']
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.dropWhile(users, 'active'); * _.dropWhile(users, 'active');
* // => objects for ['barney', 'fred', 'pebbles'] * // => objects for ['barney', 'fred', 'pebbles']
*/ */
@@ -5722,15 +5722,15 @@
* _.findIndex(users, function(o) { return o.user == 'barney'; }); * _.findIndex(users, function(o) { return o.user == 'barney'; });
* // => 0 * // => 0
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.findIndex(users, { 'user': 'fred', 'active': false }); * _.findIndex(users, { 'user': 'fred', 'active': false });
* // => 1 * // => 1
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.findIndex(users, ['active', false]); * _.findIndex(users, ['active', false]);
* // => 0 * // => 0
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.findIndex(users, 'active'); * _.findIndex(users, 'active');
* // => 2 * // => 2
*/ */
@@ -5761,15 +5761,15 @@
* _.findLastIndex(users, function(o) { return o.user == 'pebbles'; }); * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
* // => 2 * // => 2
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.findLastIndex(users, { 'user': 'barney', 'active': true }); * _.findLastIndex(users, { 'user': 'barney', 'active': true });
* // => 0 * // => 0
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.findLastIndex(users, ['active', false]); * _.findLastIndex(users, ['active', false]);
* // => 2 * // => 2
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.findLastIndex(users, 'active'); * _.findLastIndex(users, 'active');
* // => 0 * // => 0
*/ */
@@ -5906,7 +5906,7 @@
* _.indexOf([1, 2, 1, 2], 2); * _.indexOf([1, 2, 1, 2], 2);
* // => 1 * // => 1
* *
* // using `fromIndex` * // Search from the `fromIndex`.
* _.indexOf([1, 2, 1, 2], 2, 2); * _.indexOf([1, 2, 1, 2], 2, 2);
* // => 3 * // => 3
*/ */
@@ -5977,7 +5977,7 @@
* _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor); * _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
* // => [2.1] * // => [2.1]
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 1 }] * // => [{ 'x': 1 }]
*/ */
@@ -6080,7 +6080,7 @@
* _.lastIndexOf([1, 2, 1, 2], 2); * _.lastIndexOf([1, 2, 1, 2], 2);
* // => 3 * // => 3
* *
* // using `fromIndex` * // Search from the `fromIndex`.
* _.lastIndexOf([1, 2, 1, 2], 2, 2); * _.lastIndexOf([1, 2, 1, 2], 2, 2);
* // => 1 * // => 1
*/ */
@@ -6356,7 +6356,7 @@
* _.sortedIndexBy(['thirty', 'fifty'], 'forty', _.propertyOf(dict)); * _.sortedIndexBy(['thirty', 'fifty'], 'forty', _.propertyOf(dict));
* // => 1 * // => 1
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.sortedIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x'); * _.sortedIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
* // => 0 * // => 0
*/ */
@@ -6424,7 +6424,7 @@
* @returns {number} Returns the index at which `value` should be inserted into `array`. * @returns {number} Returns the index at which `value` should be inserted into `array`.
* @example * @example
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.sortedLastIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x'); * _.sortedLastIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
* // => 1 * // => 1
*/ */
@@ -6604,15 +6604,15 @@
* _.takeRightWhile(users, function(o) { return !o.active; }); * _.takeRightWhile(users, function(o) { return !o.active; });
* // => objects for ['fred', 'pebbles'] * // => objects for ['fred', 'pebbles']
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.takeRightWhile(users, { 'user': 'pebbles', 'active': false }); * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
* // => objects for ['pebbles'] * // => objects for ['pebbles']
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.takeRightWhile(users, ['active', false]); * _.takeRightWhile(users, ['active', false]);
* // => objects for ['fred', 'pebbles'] * // => objects for ['fred', 'pebbles']
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.takeRightWhile(users, 'active'); * _.takeRightWhile(users, 'active');
* // => [] * // => []
*/ */
@@ -6644,15 +6644,15 @@
* _.takeWhile(users, function(o) { return !o.active; }); * _.takeWhile(users, function(o) { return !o.active; });
* // => objects for ['barney', 'fred'] * // => objects for ['barney', 'fred']
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.takeWhile(users, { 'user': 'barney', 'active': false }); * _.takeWhile(users, { 'user': 'barney', 'active': false });
* // => objects for ['barney'] * // => objects for ['barney']
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.takeWhile(users, ['active', false]); * _.takeWhile(users, ['active', false]);
* // => objects for ['barney', 'fred'] * // => objects for ['barney', 'fred']
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.takeWhile(users, 'active'); * _.takeWhile(users, 'active');
* // => [] * // => []
*/ */
@@ -6697,7 +6697,7 @@
* _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor); * _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
* // => [2.1, 1.2, 4.3] * // => [2.1, 1.2, 4.3]
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 1 }, { 'x': 2 }] * // => [{ 'x': 1 }, { 'x': 2 }]
*/ */
@@ -6774,7 +6774,7 @@
* _.uniqBy([2.1, 1.2, 2.3], Math.floor); * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
* // => [2.1, 1.2] * // => [2.1, 1.2]
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 1 }, { 'x': 2 }] * // => [{ 'x': 1 }, { 'x': 2 }]
*/ */
@@ -6930,7 +6930,7 @@
* _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor); * _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor);
* // => [1.2, 4.3] * // => [1.2, 4.3]
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 2 }] * // => [{ 'x': 2 }]
*/ */
@@ -7188,11 +7188,11 @@
* { 'user': 'fred', 'age': 40 } * { 'user': 'fred', 'age': 40 }
* ]; * ];
* *
* // without explicit chaining * // A sequence without explicit chaining.
* _(users).head(); * _(users).head();
* // => { 'user': 'barney', 'age': 36 } * // => { 'user': 'barney', 'age': 36 }
* *
* // with explicit chaining * // A sequence with explicit chaining.
* _(users) * _(users)
* .chain() * .chain()
* .head() * .head()
@@ -7447,15 +7447,15 @@
* { 'user': 'fred', 'active': false } * { 'user': 'fred', 'active': false }
* ]; * ];
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.every(users, { 'user': 'barney', 'active': false }); * _.every(users, { 'user': 'barney', 'active': false });
* // => false * // => false
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.every(users, ['active', false]); * _.every(users, ['active', false]);
* // => true * // => true
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.every(users, 'active'); * _.every(users, 'active');
* // => false * // => false
*/ */
@@ -7488,15 +7488,15 @@
* _.filter(users, function(o) { return !o.active; }); * _.filter(users, function(o) { return !o.active; });
* // => objects for ['fred'] * // => objects for ['fred']
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.filter(users, { 'age': 36, 'active': true }); * _.filter(users, { 'age': 36, 'active': true });
* // => objects for ['barney'] * // => objects for ['barney']
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.filter(users, ['active', false]); * _.filter(users, ['active', false]);
* // => objects for ['fred'] * // => objects for ['fred']
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.filter(users, 'active'); * _.filter(users, 'active');
* // => objects for ['barney'] * // => objects for ['barney']
*/ */
@@ -7527,15 +7527,15 @@
* _.find(users, function(o) { return o.age < 40; }); * _.find(users, function(o) { return o.age < 40; });
* // => object for 'barney' * // => object for 'barney'
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.find(users, { 'age': 1, 'active': true }); * _.find(users, { 'age': 1, 'active': true });
* // => object for 'pebbles' * // => object for 'pebbles'
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.find(users, ['active', false]); * _.find(users, ['active', false]);
* // => object for 'fred' * // => object for 'fred'
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.find(users, 'active'); * _.find(users, 'active');
* // => object for 'barney' * // => object for 'barney'
*/ */
@@ -7649,7 +7649,7 @@
* _.groupBy([6.1, 4.2, 6.3], Math.floor); * _.groupBy([6.1, 4.2, 6.3], Math.floor);
* // => { '4': [4.2], '6': [6.1, 6.3] } * // => { '4': [4.2], '6': [6.1, 6.3] }
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.groupBy(['one', 'two', 'three'], 'length'); * _.groupBy(['one', 'two', 'three'], 'length');
* // => { '3': ['one', 'two'], '5': ['three'] } * // => { '3': ['one', 'two'], '5': ['three'] }
*/ */
@@ -7805,7 +7805,7 @@
* { 'user': 'fred' } * { 'user': 'fred' }
* ]; * ];
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.map(users, 'user'); * _.map(users, 'user');
* // => ['barney', 'fred'] * // => ['barney', 'fred']
*/ */
@@ -7837,7 +7837,7 @@
* { 'user': 'barney', 'age': 36 } * { 'user': 'barney', 'age': 36 }
* ]; * ];
* *
* // sort by `user` in ascending order and by `age` in descending order * // Sort by `user` in ascending order and by `age` in descending order.
* _.orderBy(users, ['user', 'age'], ['asc', 'desc']); * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
*/ */
@@ -7878,15 +7878,15 @@
* _.partition(users, function(o) { return o.active; }); * _.partition(users, function(o) { return o.active; });
* // => objects for [['fred'], ['barney', 'pebbles']] * // => objects for [['fred'], ['barney', 'pebbles']]
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.partition(users, { 'age': 1, 'active': false }); * _.partition(users, { 'age': 1, 'active': false });
* // => objects for [['pebbles'], ['barney', 'fred']] * // => objects for [['pebbles'], ['barney', 'fred']]
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.partition(users, ['active', false]); * _.partition(users, ['active', false]);
* // => objects for [['barney', 'pebbles'], ['fred']] * // => objects for [['barney', 'pebbles'], ['fred']]
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.partition(users, 'active'); * _.partition(users, 'active');
* // => objects for [['fred'], ['barney', 'pebbles']] * // => objects for [['fred'], ['barney', 'pebbles']]
*/ */
@@ -7983,15 +7983,15 @@
* _.reject(users, function(o) { return !o.active; }); * _.reject(users, function(o) { return !o.active; });
* // => objects for ['fred'] * // => objects for ['fred']
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.reject(users, { 'age': 40, 'active': true }); * _.reject(users, { 'age': 40, 'active': true });
* // => objects for ['barney'] * // => objects for ['barney']
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.reject(users, ['active', false]); * _.reject(users, ['active', false]);
* // => objects for ['fred'] * // => objects for ['fred']
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.reject(users, 'active'); * _.reject(users, 'active');
* // => objects for ['barney'] * // => objects for ['barney']
*/ */
@@ -8130,15 +8130,15 @@
* { 'user': 'fred', 'active': false } * { 'user': 'fred', 'active': false }
* ]; * ];
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.some(users, { 'user': 'barney', 'active': false }); * _.some(users, { 'user': 'barney', 'active': false });
* // => false * // => false
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.some(users, ['active', false]); * _.some(users, ['active', false]);
* // => true * // => true
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.some(users, 'active'); * _.some(users, 'active');
* // => true * // => true
*/ */
@@ -8338,7 +8338,7 @@
* bound('!'); * bound('!');
* // => 'hi fred!' * // => 'hi fred!'
* *
* // using placeholders * // Bound with placeholders.
* var bound = _.bind(greet, object, _, '!'); * var bound = _.bind(greet, object, _, '!');
* bound('hi'); * bound('hi');
* // => 'hi fred!' * // => 'hi fred!'
@@ -8391,7 +8391,7 @@
* bound('!'); * bound('!');
* // => 'hiya fred!' * // => 'hiya fred!'
* *
* // using placeholders * // Bound with placeholders.
* var bound = _.bindKey(object, 'greet', _, '!'); * var bound = _.bindKey(object, 'greet', _, '!');
* bound('hi'); * bound('hi');
* // => 'hiya fred!' * // => 'hiya fred!'
@@ -8441,7 +8441,7 @@
* curried(1, 2, 3); * curried(1, 2, 3);
* // => [1, 2, 3] * // => [1, 2, 3]
* *
* // using placeholders * // Curried with placeholders.
* curried(1)(_, 3)(2); * curried(1)(_, 3)(2);
* // => [1, 2, 3] * // => [1, 2, 3]
*/ */
@@ -8485,7 +8485,7 @@
* curried(1, 2, 3); * curried(1, 2, 3);
* // => [1, 2, 3] * // => [1, 2, 3]
* *
* // using placeholders * // Curried with placeholders.
* curried(3)(1, _)(2); * curried(3)(1, _)(2);
* // => [1, 2, 3] * // => [1, 2, 3]
*/ */
@@ -8528,21 +8528,21 @@
* @returns {Function} Returns the new debounced function. * @returns {Function} Returns the new debounced function.
* @example * @example
* *
* // avoid costly calculations while the window size is in flux * // Avoid costly calculations while the window size is in flux.
* jQuery(window).on('resize', _.debounce(calculateLayout, 150)); * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
* *
* // invoke `sendMail` when clicked, debouncing subsequent calls * // Invoke `sendMail` when clicked, debouncing subsequent calls.
* jQuery(element).on('click', _.debounce(sendMail, 300, { * jQuery(element).on('click', _.debounce(sendMail, 300, {
* 'leading': true, * 'leading': true,
* 'trailing': false * 'trailing': false
* })); * }));
* *
* // ensure `batchLog` is invoked once after 1 second of debounced calls * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
* var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
* var source = new EventSource('/stream'); * var source = new EventSource('/stream');
* jQuery(source).on('message', debounced); * jQuery(source).on('message', debounced);
* *
* // cancel a trailing debounced invocation * // Cancel the trailing debounced invocation.
* jQuery(window).on('popstate', debounced.cancel); * jQuery(window).on('popstate', debounced.cancel);
*/ */
function debounce(func, wait, options) { function debounce(func, wait, options) {
@@ -8675,7 +8675,7 @@
* _.defer(function(text) { * _.defer(function(text) {
* console.log(text); * console.log(text);
* }, 'deferred'); * }, 'deferred');
* // logs 'deferred' after one or more milliseconds * // => logs 'deferred' after one or more milliseconds
*/ */
var defer = rest(function(func, args) { var defer = rest(function(func, args) {
return baseDelay(func, 1, args); return baseDelay(func, 1, args);
@@ -8758,12 +8758,12 @@
* values(object); * values(object);
* // => [1, 2] * // => [1, 2]
* *
* // modifying the result cache * // Modify the result cache.
* values.cache.set(object, ['a', 'b']); * values.cache.set(object, ['a', 'b']);
* values(object); * values(object);
* // => ['a', 'b'] * // => ['a', 'b']
* *
* // replacing `_.memoize.Cache` * // Replace `_.memoize.Cache`.
* _.memoize.Cache = WeakMap; * _.memoize.Cache = WeakMap;
*/ */
function memoize(func, resolver) { function memoize(func, resolver) {
@@ -8908,7 +8908,7 @@
* sayHelloTo('fred'); * sayHelloTo('fred');
* // => 'hello fred' * // => 'hello fred'
* *
* // using placeholders * // Partially applied with placeholders.
* var greetFred = _.partial(greet, _, 'fred'); * var greetFred = _.partial(greet, _, 'fred');
* greetFred('hi'); * greetFred('hi');
* // => 'hi fred' * // => 'hi fred'
@@ -8944,7 +8944,7 @@
* greetFred('hi'); * greetFred('hi');
* // => 'hi fred' * // => 'hi fred'
* *
* // using placeholders * // Partially applied with placeholders.
* var sayHelloTo = _.partialRight(greet, 'hello', _); * var sayHelloTo = _.partialRight(greet, 'hello', _);
* sayHelloTo('fred'); * sayHelloTo('fred');
* // => 'hello fred' * // => 'hello fred'
@@ -9051,7 +9051,6 @@
* say(['fred', 'hello']); * say(['fred', 'hello']);
* // => 'fred says hello' * // => 'fred says hello'
* *
* // with a Promise
* var numbers = Promise.all([ * var numbers = Promise.all([
* Promise.resolve(40), * Promise.resolve(40),
* Promise.resolve(36) * Promise.resolve(36)
@@ -9101,14 +9100,14 @@
* @returns {Function} Returns the new throttled function. * @returns {Function} Returns the new throttled function.
* @example * @example
* *
* // avoid excessively updating the position while scrolling * // Avoid excessively updating the position while scrolling.
* jQuery(window).on('scroll', _.throttle(updatePosition, 100)); * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
* *
* // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false }); * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
* jQuery(element).on('click', throttled); * jQuery(element).on('click', throttled);
* *
* // cancel a trailing throttled invocation * // Cancel the trailing throttled invocation.
* jQuery(window).on('popstate', throttled.cancel); * jQuery(window).on('popstate', throttled.cancel);
*/ */
function throttle(func, wait, options) { function throttle(func, wait, options) {
@@ -10727,15 +10726,15 @@
* _.findKey(users, function(o) { return o.age < 40; }); * _.findKey(users, function(o) { return o.age < 40; });
* // => 'barney' (iteration order is not guaranteed) * // => 'barney' (iteration order is not guaranteed)
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.findKey(users, { 'age': 1, 'active': true }); * _.findKey(users, { 'age': 1, 'active': true });
* // => 'pebbles' * // => 'pebbles'
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.findKey(users, ['active', false]); * _.findKey(users, ['active', false]);
* // => 'fred' * // => 'fred'
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.findKey(users, 'active'); * _.findKey(users, 'active');
* // => 'barney' * // => 'barney'
*/ */
@@ -10764,15 +10763,15 @@
* _.findLastKey(users, function(o) { return o.age < 40; }); * _.findLastKey(users, function(o) { return o.age < 40; });
* // => returns 'pebbles' assuming `_.findKey` returns 'barney' * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
* *
* // using the `_.matches` iteratee shorthand * // The `_.matches` iteratee shorthand.
* _.findLastKey(users, { 'age': 36, 'active': true }); * _.findLastKey(users, { 'age': 36, 'active': true });
* // => 'barney' * // => 'barney'
* *
* // using the `_.matchesProperty` iteratee shorthand * // The `_.matchesProperty` iteratee shorthand.
* _.findLastKey(users, ['active', false]); * _.findLastKey(users, ['active', false]);
* // => 'fred' * // => 'fred'
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.findLastKey(users, 'active'); * _.findLastKey(users, 'active');
* // => 'pebbles' * // => 'pebbles'
*/ */
@@ -11245,7 +11244,7 @@
* _.mapValues(users, function(o) { return o.age; }); * _.mapValues(users, function(o) { return o.age; });
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.mapValues(users, 'age'); * _.mapValues(users, 'age');
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
*/ */
@@ -12409,54 +12408,54 @@
* @returns {Function} Returns the compiled template function. * @returns {Function} Returns the compiled template function.
* @example * @example
* *
* // using the "interpolate" delimiter to create a compiled template * // Use the "interpolate" delimiter to create a compiled template.
* var compiled = _.template('hello <%= user %>!'); * var compiled = _.template('hello <%= user %>!');
* compiled({ 'user': 'fred' }); * compiled({ 'user': 'fred' });
* // => 'hello fred!' * // => 'hello fred!'
* *
* // using the HTML "escape" delimiter to escape data property values * // Use the HTML "escape" delimiter to escape data property values.
* var compiled = _.template('<b><%- value %></b>'); * var compiled = _.template('<b><%- value %></b>');
* compiled({ 'value': '<script>' }); * compiled({ 'value': '<script>' });
* // => '<b>&lt;script&gt;</b>' * // => '<b>&lt;script&gt;</b>'
* *
* // using the "evaluate" delimiter to execute JavaScript and generate HTML * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
* var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>'); * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
* compiled({ 'users': ['fred', 'barney'] }); * compiled({ 'users': ['fred', 'barney'] });
* // => '<li>fred</li><li>barney</li>' * // => '<li>fred</li><li>barney</li>'
* *
* // using the internal `print` function in "evaluate" delimiters * // Use the internal `print` function in "evaluate" delimiters.
* var compiled = _.template('<% print("hello " + user); %>!'); * var compiled = _.template('<% print("hello " + user); %>!');
* compiled({ 'user': 'barney' }); * compiled({ 'user': 'barney' });
* // => 'hello barney!' * // => 'hello barney!'
* *
* // using the ES delimiter as an alternative to the default "interpolate" delimiter * // Use the ES delimiter as an alternative to the default "interpolate" delimiter.
* var compiled = _.template('hello ${ user }!'); * var compiled = _.template('hello ${ user }!');
* compiled({ 'user': 'pebbles' }); * compiled({ 'user': 'pebbles' });
* // => 'hello pebbles!' * // => 'hello pebbles!'
* *
* // using custom template delimiters * // Use custom template delimiters.
* _.templateSettings.interpolate = /{{([\s\S]+?)}}/g; * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
* var compiled = _.template('hello {{ user }}!'); * var compiled = _.template('hello {{ user }}!');
* compiled({ 'user': 'mustache' }); * compiled({ 'user': 'mustache' });
* // => 'hello mustache!' * // => 'hello mustache!'
* *
* // using backslashes to treat delimiters as plain text * // Use backslashes to treat delimiters as plain text.
* var compiled = _.template('<%= "\\<%- value %\\>" %>'); * var compiled = _.template('<%= "\\<%- value %\\>" %>');
* compiled({ 'value': 'ignored' }); * compiled({ 'value': 'ignored' });
* // => '<%- value %>' * // => '<%- value %>'
* *
* // using the `imports` option to import `jQuery` as `jq` * // Use the `imports` option to import `jQuery` as `jq`.
* var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>'; * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
* var compiled = _.template(text, { 'imports': { 'jq': jQuery } }); * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
* compiled({ 'users': ['fred', 'barney'] }); * compiled({ 'users': ['fred', 'barney'] });
* // => '<li>fred</li><li>barney</li>' * // => '<li>fred</li><li>barney</li>'
* *
* // using the `sourceURL` option to specify a custom sourceURL for the template * // Use the `sourceURL` option to specify a custom sourceURL for the template.
* var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' }); * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
* compiled(data); * compiled(data);
* // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
* *
* // using the `variable` option to ensure a with-statement isn't used in the compiled template * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
* var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' }); * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
* compiled.source; * compiled.source;
* // => function(data) { * // => function(data) {
@@ -12465,8 +12464,8 @@
* // return __p; * // return __p;
* // } * // }
* *
* // using the `source` property to inline compiled templates for meaningful * // Use the `source` property to inline compiled templates for meaningful
* // line numbers in error messages and a stack trace * // line numbers in error messages and stack traces.
* fs.writeFileSync(path.join(cwd, 'jst.js'), '\ * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
* var JST = {\ * var JST = {\
* "main": ' + _.template(mainText).source + '\ * "main": ' + _.template(mainText).source + '\
@@ -12913,7 +12912,7 @@
* @returns {*} Returns the `func` result or error object. * @returns {*} Returns the `func` result or error object.
* @example * @example
* *
* // avoid throwing errors for invalid selectors * // Avoid throwing errors for invalid selectors.
* var elements = _.attempt(function(selector) { * var elements = _.attempt(function(selector) {
* return document.querySelectorAll(selector); * return document.querySelectorAll(selector);
* }, '>_>'); * }, '>_>');
@@ -13139,7 +13138,7 @@
* { 'user': 'fred', 'age': 40 } * { 'user': 'fred', 'age': 40 }
* ]; * ];
* *
* // create custom iteratee shorthands * // Create custom iteratee shorthands.
* _.iteratee = _.wrap(_.iteratee, function(callback, func) { * _.iteratee = _.wrap(_.iteratee, function(callback, func) {
* var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func); * var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
* return !p ? callback(func) : function(object) { * return !p ? callback(func) : function(object) {
@@ -13789,7 +13788,7 @@
* _.maxBy(objects, function(o) { return o.n; }); * _.maxBy(objects, function(o) { return o.n; });
* // => { 'n': 2 } * // => { 'n': 2 }
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.maxBy(objects, 'n'); * _.maxBy(objects, 'n');
* // => { 'n': 2 } * // => { 'n': 2 }
*/ */
@@ -13857,7 +13856,7 @@
* _.minBy(objects, function(o) { return o.n; }); * _.minBy(objects, function(o) { return o.n; });
* // => { 'n': 1 } * // => { 'n': 1 }
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.minBy(objects, 'n'); * _.minBy(objects, 'n');
* // => { 'n': 1 } * // => { 'n': 1 }
*/ */
@@ -13951,7 +13950,7 @@
* _.sumBy(objects, function(o) { return o.n; }); * _.sumBy(objects, function(o) { return o.n; });
* // => 20 * // => 20
* *
* // using the `_.property` iteratee shorthand * // The `_.property` iteratee shorthand.
* _.sumBy(objects, 'n'); * _.sumBy(objects, 'n');
* // => 20 * // => 20
*/ */