Skip to content
Myr

Refactoring callback()

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

authored by visionmedia · committed by visionmedia · parent 2a04a15 · Browse files · 2 files+13 added−4 removed
This commit

State

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

Diff stats

2 files+13 added−4 removed

  • tests:+8 added−0 removed
  • other:+5 added−4 removed

2 files+13 added−4 removed

modified:lib/express/collection.js+5 added-4 removed
11 unmodified lines
12 * passed convert the shorthand expr to a function.13 *14 * - Functions are passed through un-touched15 * - Strings with length of < 4 are considered operators between a and b16 * - Single words are considered properties on a17 * - Single functions are considered method calls on a18 * - Larger strings are considered return expressions19 *20 * @param {string, function} fn21 * @return {function}
1 unmodified line
23 */2425function callback(fn) {26 if (fn === undefined) return25 return fn instanceof Function ? fn :26 fn.length < 4 ?27 Function('a, b, c', 'return a ' + fn + ' b') :28 Function('a, b, c', 'return ' + fn)27 if (fn instanceof Function) return fn28 if (fn.length < 4) return Function('a, b, c', 'return a ' + fn + ' b')29 return Function('a, b, c', 'return ' + fn)30}3132// --- Collection33
491 unmodified lines
modified:spec/spec.collection.js+8 added
33 unmodified lines
34 it 'should be considered a return expression'35 $(5..1).sort('a - b').toArray().should.eql 1..536 $(5..1).reduce(0, 'a + b').should.eql 1537 end38 39 it 'should consider a single word a property on a'40 $(['foo', 'foobar']).map('length').toArray().should.eql [3, 6]41 end42 43 it 'should consider a single function a method on a'44 $(['foo', 'foobar']).map('charAt(0)').toArray().should.eql ['f', 'f']45 end46 end47 end48 49 describe '#at()'
404 unmodified lines