Ticket #221: itemgetter_array.patch
| File itemgetter_array.patch, 1.2 kB (added by arnarbi@gmail.com, 2 years ago) |
|---|
-
MochiKit/Base.js
old new 318 318 319 319 /** @id MochiKit.Base.itemgetter */ 320 320 itemgetter: function (func) { 321 return function (arg) { 322 return arg[func]; 323 }; 321 if (MochiKit.Base.isArrayLike(func)) 322 return function(arg) { 323 return map(function (f) { return arg[f]; }, func); 324 } 325 else 326 return function (arg) { 327 return arg[func]; 328 }; 324 329 }, 325 330 326 331 /** @id MochiKit.Base.typeMatcher */ -
tests/test_Base.js
old new 499 499 500 500 t.is( queryString([["foo", "bar"], ["baz", "wibble"]]), "foo=baz&bar=wibble" ); 501 501 502 /* test itemgetter */ 503 var o = {a: 1, b: 2, c: 4, d: -1}; 504 t.is( itemgetter('c')(o), 4 ); 505 t.is( itemgetter('x')(o), undefined ); 506 t.is( repr(itemgetter(['a', 'c', 'd'])(o)), repr([1, 4, -1]) ); 507 t.is( repr(itemgetter(['a', 'x', 'd'])(o)), repr([1, undefined, -1]) ); 508 502 509 };
