Skip to content
Myr

Shorthand expressions consider single word as prop, single func as method

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent d3c5b03 · Browse files · 1 file+5 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−0 removed

  • other:+5 added−0 removed

1 file+5 added−0 removed

modified:lib/express/collection.js+5 added
5 unmodified lines
6 */78$break = '__break__'910var property = /^\w+$/,11 method = /^\w+\(/1213/**14 * Normalize callback _fn_. When a string is15 * passed convert the shorthand expr to a function.16 *
11 unmodified lines
28function callback(fn) {29 if (fn === undefined) return30 if (fn instanceof Function) return fn31 if (fn.length < 4) return Function('a, b, c', 'return a ' + fn + ' b')32 if (property.test(fn) ||33 method.test(fn)) fn = 'a.' + fn34 return Function('a, b, c', 'return ' + fn)35}3637// --- Collection
492 unmodified lines