mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 14:37:49 +00:00
Make doc code sample comments match source comment style. [ci skip]
This commit is contained in:
189
lodash.js
189
lodash.js
@@ -1254,14 +1254,14 @@
|
||||
* lodash.isFunction(lodash.bar);
|
||||
* // => true
|
||||
*
|
||||
* // using `context` to mock `Date#getTime` use in `_.now`
|
||||
* // Use `context` to mock `Date#getTime` use in `_.now`.
|
||||
* var mock = _.runInContext({
|
||||
* 'Date': function() {
|
||||
* 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;
|
||||
*/
|
||||
function runInContext(context) {
|
||||
@@ -1451,11 +1451,11 @@
|
||||
*
|
||||
* var wrapped = _([1, 2, 3]);
|
||||
*
|
||||
* // returns an unwrapped value
|
||||
* // Returns an unwrapped value.
|
||||
* wrapped.reduce(_.add);
|
||||
* // => 6
|
||||
*
|
||||
* // returns a wrapped value
|
||||
* // Returns a wrapped value.
|
||||
* var squares = wrapped.map(square);
|
||||
*
|
||||
* _.isArray(squares);
|
||||
@@ -5471,7 +5471,7 @@
|
||||
* _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
|
||||
* // => [3.1, 1.3]
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
|
||||
* // => [{ 'x': 2 }]
|
||||
*/
|
||||
@@ -5603,15 +5603,15 @@
|
||||
* _.dropRightWhile(users, function(o) { return !o.active; });
|
||||
* // => objects for ['barney']
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
|
||||
* // => objects for ['barney', 'fred']
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.dropRightWhile(users, ['active', false]);
|
||||
* // => objects for ['barney']
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.dropRightWhile(users, 'active');
|
||||
* // => objects for ['barney', 'fred', 'pebbles']
|
||||
*/
|
||||
@@ -5643,15 +5643,15 @@
|
||||
* _.dropWhile(users, function(o) { return !o.active; });
|
||||
* // => objects for ['pebbles']
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.dropWhile(users, { 'user': 'barney', 'active': false });
|
||||
* // => objects for ['fred', 'pebbles']
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.dropWhile(users, ['active', false]);
|
||||
* // => objects for ['pebbles']
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.dropWhile(users, 'active');
|
||||
* // => objects for ['barney', 'fred', 'pebbles']
|
||||
*/
|
||||
@@ -5722,15 +5722,15 @@
|
||||
* _.findIndex(users, function(o) { return o.user == 'barney'; });
|
||||
* // => 0
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.findIndex(users, { 'user': 'fred', 'active': false });
|
||||
* // => 1
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.findIndex(users, ['active', false]);
|
||||
* // => 0
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.findIndex(users, 'active');
|
||||
* // => 2
|
||||
*/
|
||||
@@ -5761,15 +5761,15 @@
|
||||
* _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
|
||||
* // => 2
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.findLastIndex(users, { 'user': 'barney', 'active': true });
|
||||
* // => 0
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.findLastIndex(users, ['active', false]);
|
||||
* // => 2
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.findLastIndex(users, 'active');
|
||||
* // => 0
|
||||
*/
|
||||
@@ -5906,7 +5906,7 @@
|
||||
* _.indexOf([1, 2, 1, 2], 2);
|
||||
* // => 1
|
||||
*
|
||||
* // using `fromIndex`
|
||||
* // Search from the `fromIndex`.
|
||||
* _.indexOf([1, 2, 1, 2], 2, 2);
|
||||
* // => 3
|
||||
*/
|
||||
@@ -5977,7 +5977,7 @@
|
||||
* _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
|
||||
* // => [2.1]
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
||||
* // => [{ 'x': 1 }]
|
||||
*/
|
||||
@@ -6080,7 +6080,7 @@
|
||||
* _.lastIndexOf([1, 2, 1, 2], 2);
|
||||
* // => 3
|
||||
*
|
||||
* // using `fromIndex`
|
||||
* // Search from the `fromIndex`.
|
||||
* _.lastIndexOf([1, 2, 1, 2], 2, 2);
|
||||
* // => 1
|
||||
*/
|
||||
@@ -6356,7 +6356,7 @@
|
||||
* _.sortedIndexBy(['thirty', 'fifty'], 'forty', _.propertyOf(dict));
|
||||
* // => 1
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.sortedIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
|
||||
* // => 0
|
||||
*/
|
||||
@@ -6424,7 +6424,7 @@
|
||||
* @returns {number} Returns the index at which `value` should be inserted into `array`.
|
||||
* @example
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.sortedLastIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
|
||||
* // => 1
|
||||
*/
|
||||
@@ -6604,15 +6604,15 @@
|
||||
* _.takeRightWhile(users, function(o) { return !o.active; });
|
||||
* // => objects for ['fred', 'pebbles']
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
|
||||
* // => objects for ['pebbles']
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.takeRightWhile(users, ['active', false]);
|
||||
* // => objects for ['fred', 'pebbles']
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.takeRightWhile(users, 'active');
|
||||
* // => []
|
||||
*/
|
||||
@@ -6644,15 +6644,15 @@
|
||||
* _.takeWhile(users, function(o) { return !o.active; });
|
||||
* // => objects for ['barney', 'fred']
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.takeWhile(users, { 'user': 'barney', 'active': false });
|
||||
* // => objects for ['barney']
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.takeWhile(users, ['active', false]);
|
||||
* // => objects for ['barney', 'fred']
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.takeWhile(users, 'active');
|
||||
* // => []
|
||||
*/
|
||||
@@ -6697,7 +6697,7 @@
|
||||
* _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
|
||||
* // => [2.1, 1.2, 4.3]
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
||||
* // => [{ 'x': 1 }, { 'x': 2 }]
|
||||
*/
|
||||
@@ -6774,7 +6774,7 @@
|
||||
* _.uniqBy([2.1, 1.2, 2.3], Math.floor);
|
||||
* // => [2.1, 1.2]
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
|
||||
* // => [{ 'x': 1 }, { 'x': 2 }]
|
||||
*/
|
||||
@@ -6930,7 +6930,7 @@
|
||||
* _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor);
|
||||
* // => [1.2, 4.3]
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
||||
* // => [{ 'x': 2 }]
|
||||
*/
|
||||
@@ -7188,11 +7188,11 @@
|
||||
* { 'user': 'fred', 'age': 40 }
|
||||
* ];
|
||||
*
|
||||
* // without explicit chaining
|
||||
* // A sequence without explicit chaining.
|
||||
* _(users).head();
|
||||
* // => { 'user': 'barney', 'age': 36 }
|
||||
*
|
||||
* // with explicit chaining
|
||||
* // A sequence with explicit chaining.
|
||||
* _(users)
|
||||
* .chain()
|
||||
* .head()
|
||||
@@ -7447,15 +7447,15 @@
|
||||
* { 'user': 'fred', 'active': false }
|
||||
* ];
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.every(users, { 'user': 'barney', 'active': false });
|
||||
* // => false
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.every(users, ['active', false]);
|
||||
* // => true
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.every(users, 'active');
|
||||
* // => false
|
||||
*/
|
||||
@@ -7488,15 +7488,15 @@
|
||||
* _.filter(users, function(o) { return !o.active; });
|
||||
* // => objects for ['fred']
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.filter(users, { 'age': 36, 'active': true });
|
||||
* // => objects for ['barney']
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.filter(users, ['active', false]);
|
||||
* // => objects for ['fred']
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.filter(users, 'active');
|
||||
* // => objects for ['barney']
|
||||
*/
|
||||
@@ -7527,15 +7527,15 @@
|
||||
* _.find(users, function(o) { return o.age < 40; });
|
||||
* // => object for 'barney'
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.find(users, { 'age': 1, 'active': true });
|
||||
* // => object for 'pebbles'
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.find(users, ['active', false]);
|
||||
* // => object for 'fred'
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.find(users, 'active');
|
||||
* // => object for 'barney'
|
||||
*/
|
||||
@@ -7649,7 +7649,7 @@
|
||||
* _.groupBy([6.1, 4.2, 6.3], Math.floor);
|
||||
* // => { '4': [4.2], '6': [6.1, 6.3] }
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.groupBy(['one', 'two', 'three'], 'length');
|
||||
* // => { '3': ['one', 'two'], '5': ['three'] }
|
||||
*/
|
||||
@@ -7805,7 +7805,7 @@
|
||||
* { 'user': 'fred' }
|
||||
* ];
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.map(users, 'user');
|
||||
* // => ['barney', 'fred']
|
||||
*/
|
||||
@@ -7837,7 +7837,7 @@
|
||||
* { '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']);
|
||||
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
|
||||
*/
|
||||
@@ -7878,15 +7878,15 @@
|
||||
* _.partition(users, function(o) { return o.active; });
|
||||
* // => objects for [['fred'], ['barney', 'pebbles']]
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.partition(users, { 'age': 1, 'active': false });
|
||||
* // => objects for [['pebbles'], ['barney', 'fred']]
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.partition(users, ['active', false]);
|
||||
* // => objects for [['barney', 'pebbles'], ['fred']]
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.partition(users, 'active');
|
||||
* // => objects for [['fred'], ['barney', 'pebbles']]
|
||||
*/
|
||||
@@ -7983,15 +7983,15 @@
|
||||
* _.reject(users, function(o) { return !o.active; });
|
||||
* // => objects for ['fred']
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.reject(users, { 'age': 40, 'active': true });
|
||||
* // => objects for ['barney']
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.reject(users, ['active', false]);
|
||||
* // => objects for ['fred']
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.reject(users, 'active');
|
||||
* // => objects for ['barney']
|
||||
*/
|
||||
@@ -8130,15 +8130,15 @@
|
||||
* { 'user': 'fred', 'active': false }
|
||||
* ];
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.some(users, { 'user': 'barney', 'active': false });
|
||||
* // => false
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.some(users, ['active', false]);
|
||||
* // => true
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.some(users, 'active');
|
||||
* // => true
|
||||
*/
|
||||
@@ -8338,7 +8338,7 @@
|
||||
* bound('!');
|
||||
* // => 'hi fred!'
|
||||
*
|
||||
* // using placeholders
|
||||
* // Bound with placeholders.
|
||||
* var bound = _.bind(greet, object, _, '!');
|
||||
* bound('hi');
|
||||
* // => 'hi fred!'
|
||||
@@ -8391,7 +8391,7 @@
|
||||
* bound('!');
|
||||
* // => 'hiya fred!'
|
||||
*
|
||||
* // using placeholders
|
||||
* // Bound with placeholders.
|
||||
* var bound = _.bindKey(object, 'greet', _, '!');
|
||||
* bound('hi');
|
||||
* // => 'hiya fred!'
|
||||
@@ -8441,7 +8441,7 @@
|
||||
* curried(1, 2, 3);
|
||||
* // => [1, 2, 3]
|
||||
*
|
||||
* // using placeholders
|
||||
* // Curried with placeholders.
|
||||
* curried(1)(_, 3)(2);
|
||||
* // => [1, 2, 3]
|
||||
*/
|
||||
@@ -8485,7 +8485,7 @@
|
||||
* curried(1, 2, 3);
|
||||
* // => [1, 2, 3]
|
||||
*
|
||||
* // using placeholders
|
||||
* // Curried with placeholders.
|
||||
* curried(3)(1, _)(2);
|
||||
* // => [1, 2, 3]
|
||||
*/
|
||||
@@ -8528,21 +8528,21 @@
|
||||
* @returns {Function} Returns the new debounced function.
|
||||
* @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));
|
||||
*
|
||||
* // invoke `sendMail` when clicked, debouncing subsequent calls
|
||||
* // Invoke `sendMail` when clicked, debouncing subsequent calls.
|
||||
* jQuery(element).on('click', _.debounce(sendMail, 300, {
|
||||
* 'leading': true,
|
||||
* '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 source = new EventSource('/stream');
|
||||
* jQuery(source).on('message', debounced);
|
||||
*
|
||||
* // cancel a trailing debounced invocation
|
||||
* // Cancel the trailing debounced invocation.
|
||||
* jQuery(window).on('popstate', debounced.cancel);
|
||||
*/
|
||||
function debounce(func, wait, options) {
|
||||
@@ -8675,7 +8675,7 @@
|
||||
* _.defer(function(text) {
|
||||
* console.log(text);
|
||||
* }, 'deferred');
|
||||
* // logs 'deferred' after one or more milliseconds
|
||||
* // => logs 'deferred' after one or more milliseconds
|
||||
*/
|
||||
var defer = rest(function(func, args) {
|
||||
return baseDelay(func, 1, args);
|
||||
@@ -8758,12 +8758,12 @@
|
||||
* values(object);
|
||||
* // => [1, 2]
|
||||
*
|
||||
* // modifying the result cache
|
||||
* // Modify the result cache.
|
||||
* values.cache.set(object, ['a', 'b']);
|
||||
* values(object);
|
||||
* // => ['a', 'b']
|
||||
*
|
||||
* // replacing `_.memoize.Cache`
|
||||
* // Replace `_.memoize.Cache`.
|
||||
* _.memoize.Cache = WeakMap;
|
||||
*/
|
||||
function memoize(func, resolver) {
|
||||
@@ -8908,7 +8908,7 @@
|
||||
* sayHelloTo('fred');
|
||||
* // => 'hello fred'
|
||||
*
|
||||
* // using placeholders
|
||||
* // Partially applied with placeholders.
|
||||
* var greetFred = _.partial(greet, _, 'fred');
|
||||
* greetFred('hi');
|
||||
* // => 'hi fred'
|
||||
@@ -8944,7 +8944,7 @@
|
||||
* greetFred('hi');
|
||||
* // => 'hi fred'
|
||||
*
|
||||
* // using placeholders
|
||||
* // Partially applied with placeholders.
|
||||
* var sayHelloTo = _.partialRight(greet, 'hello', _);
|
||||
* sayHelloTo('fred');
|
||||
* // => 'hello fred'
|
||||
@@ -9051,7 +9051,6 @@
|
||||
* say(['fred', 'hello']);
|
||||
* // => 'fred says hello'
|
||||
*
|
||||
* // with a Promise
|
||||
* var numbers = Promise.all([
|
||||
* Promise.resolve(40),
|
||||
* Promise.resolve(36)
|
||||
@@ -9101,14 +9100,14 @@
|
||||
* @returns {Function} Returns the new throttled function.
|
||||
* @example
|
||||
*
|
||||
* // avoid excessively updating the position while scrolling
|
||||
* // Avoid excessively updating the position while scrolling.
|
||||
* 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 });
|
||||
* jQuery(element).on('click', throttled);
|
||||
*
|
||||
* // cancel a trailing throttled invocation
|
||||
* // Cancel the trailing throttled invocation.
|
||||
* jQuery(window).on('popstate', throttled.cancel);
|
||||
*/
|
||||
function throttle(func, wait, options) {
|
||||
@@ -10727,15 +10726,15 @@
|
||||
* _.findKey(users, function(o) { return o.age < 40; });
|
||||
* // => 'barney' (iteration order is not guaranteed)
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.findKey(users, { 'age': 1, 'active': true });
|
||||
* // => 'pebbles'
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.findKey(users, ['active', false]);
|
||||
* // => 'fred'
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.findKey(users, 'active');
|
||||
* // => 'barney'
|
||||
*/
|
||||
@@ -10764,15 +10763,15 @@
|
||||
* _.findLastKey(users, function(o) { return o.age < 40; });
|
||||
* // => returns 'pebbles' assuming `_.findKey` returns 'barney'
|
||||
*
|
||||
* // using the `_.matches` iteratee shorthand
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.findLastKey(users, { 'age': 36, 'active': true });
|
||||
* // => 'barney'
|
||||
*
|
||||
* // using the `_.matchesProperty` iteratee shorthand
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.findLastKey(users, ['active', false]);
|
||||
* // => 'fred'
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.findLastKey(users, 'active');
|
||||
* // => 'pebbles'
|
||||
*/
|
||||
@@ -11245,7 +11244,7 @@
|
||||
* _.mapValues(users, function(o) { return o.age; });
|
||||
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.mapValues(users, 'age');
|
||||
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
||||
*/
|
||||
@@ -12409,54 +12408,54 @@
|
||||
* @returns {Function} Returns the compiled template function.
|
||||
* @example
|
||||
*
|
||||
* // using the "interpolate" delimiter to create a compiled template
|
||||
* // Use the "interpolate" delimiter to create a compiled template.
|
||||
* var compiled = _.template('hello <%= user %>!');
|
||||
* compiled({ 'user': '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>');
|
||||
* compiled({ 'value': '<script>' });
|
||||
* // => '<b><script></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><% }); %>');
|
||||
* compiled({ 'users': ['fred', 'barney'] });
|
||||
* // => '<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); %>!');
|
||||
* compiled({ 'user': '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 }!');
|
||||
* compiled({ 'user': 'pebbles' });
|
||||
* // => 'hello pebbles!'
|
||||
*
|
||||
* // using custom template delimiters
|
||||
* // Use custom template delimiters.
|
||||
* _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
||||
* var compiled = _.template('hello {{ user }}!');
|
||||
* compiled({ 'user': 'mustache' });
|
||||
* // => 'hello mustache!'
|
||||
*
|
||||
* // using backslashes to treat delimiters as plain text
|
||||
* // Use backslashes to treat delimiters as plain text.
|
||||
* var compiled = _.template('<%= "\\<%- value %\\>" %>');
|
||||
* compiled({ 'value': 'ignored' });
|
||||
* // => '<%- 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 compiled = _.template(text, { 'imports': { 'jq': jQuery } });
|
||||
* compiled({ 'users': ['fred', 'barney'] });
|
||||
* // => '<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' });
|
||||
* compiled(data);
|
||||
* // => 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' });
|
||||
* compiled.source;
|
||||
* // => function(data) {
|
||||
@@ -12465,8 +12464,8 @@
|
||||
* // return __p;
|
||||
* // }
|
||||
*
|
||||
* // using the `source` property to inline compiled templates for meaningful
|
||||
* // line numbers in error messages and a stack trace
|
||||
* // Use the `source` property to inline compiled templates for meaningful
|
||||
* // line numbers in error messages and stack traces.
|
||||
* fs.writeFileSync(path.join(cwd, 'jst.js'), '\
|
||||
* var JST = {\
|
||||
* "main": ' + _.template(mainText).source + '\
|
||||
@@ -12913,7 +12912,7 @@
|
||||
* @returns {*} Returns the `func` result or error object.
|
||||
* @example
|
||||
*
|
||||
* // avoid throwing errors for invalid selectors
|
||||
* // Avoid throwing errors for invalid selectors.
|
||||
* var elements = _.attempt(function(selector) {
|
||||
* return document.querySelectorAll(selector);
|
||||
* }, '>_>');
|
||||
@@ -13139,7 +13138,7 @@
|
||||
* { 'user': 'fred', 'age': 40 }
|
||||
* ];
|
||||
*
|
||||
* // create custom iteratee shorthands
|
||||
* // Create custom iteratee shorthands.
|
||||
* _.iteratee = _.wrap(_.iteratee, function(callback, func) {
|
||||
* var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
|
||||
* return !p ? callback(func) : function(object) {
|
||||
@@ -13789,7 +13788,7 @@
|
||||
* _.maxBy(objects, function(o) { return o.n; });
|
||||
* // => { 'n': 2 }
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.maxBy(objects, 'n');
|
||||
* // => { 'n': 2 }
|
||||
*/
|
||||
@@ -13857,7 +13856,7 @@
|
||||
* _.minBy(objects, function(o) { return o.n; });
|
||||
* // => { 'n': 1 }
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.minBy(objects, 'n');
|
||||
* // => { 'n': 1 }
|
||||
*/
|
||||
@@ -13951,7 +13950,7 @@
|
||||
* _.sumBy(objects, function(o) { return o.n; });
|
||||
* // => 20
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.sumBy(objects, 'n');
|
||||
* // => 20
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user