MCPcopy
hub / github.com/stemkoski/stemkoski.github.com / invoke

Function invoke

MathBox/mathbox-bundle.js:38582–38593  ·  view source on GitHub ↗

* Invokes the method named by `methodName` on each element in the `collection` * returning an array of the results of each invoked method. Additional arguments * will be provided to each invoked method. If `methodName` is a function it * will be invoked for, and `this` bound to, each

(collection, methodName)

Source from the content-addressed store, hash-verified

38580 * // => [['1', '2', '3'], ['4', '5', '6']]
38581 */
38582 function invoke(collection, methodName) {
38583 var args = slice(arguments, 2),
38584 index = -1,
38585 isFunc = typeof methodName == 'function',
38586 length = collection ? collection.length : 0,
38587 result = Array(typeof length == 'number' ? length : 0);
38588
38589 forEach(collection, function(value) {
38590 result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args);
38591 });
38592 return result;
38593 }
38594
38595 /**
38596 * Creates an array of values by running each element in the collection

Callers

nothing calls this directly

Calls 2

sliceFunction · 0.85
forEachFunction · 0.70

Tested by

no test coverage detected