Ticket #221: rowgetter.2.patch
| File rowgetter.2.patch, 2.0 kB (added by arnarbi@gmail.com, 2 years ago) |
|---|
-
doc/rst/MochiKit/Base.rst
old new 1277 1277 Available in MochiKit 1.3.1+ 1278 1278 1279 1279 1280 :mochidef:`rowgetter(names)`: 1281 1282 Returns a ``function(obj)`` that returns ``[obj[name1], obj[name2], ..., obj[nameN]]`` 1283 where ``names`` is the array ``[name1, name2, ..., nameN]`` 1284 1285 *Availability*: 1286 Available in MochiKit 1.4+ 1287 1288 1280 1289 :mochidef:`serializeJSON(anObject)`: 1281 1290 1282 1291 Serialize ``anObject`` in the JSON [1]_ format, see `JSON -
MochiKit/Base.js
old new 323 323 }; 324 324 }, 325 325 326 /** @id MochiKit.Base.rowgetter */ 327 rowgetter: function (funcs) { 328 return function(arg) { 329 return map(function (f) { return arg[f]; }, funcs); 330 }; 331 }, 332 326 333 /** @id MochiKit.Base.typeMatcher */ 327 334 typeMatcher: function (/* typ */) { 328 335 var types = {}; … … 1226 1233 "operator", 1227 1234 "forwardCall", 1228 1235 "itemgetter", 1236 "rowgetter", 1229 1237 "typeMatcher", 1230 1238 "isCallable", 1231 1239 "isUndefined", -
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, "itemgetter, item exists" ); 505 t.is( itemgetter('x')(o), undefined, "itemgetter, item doesn't exist" ); 506 507 /* test rowgetter */ 508 var o = {a: 1, b: 2, c: 4, d: -1}; 509 t.is( repr(rowgetter(['a', 'c', 'd'])(o)), repr([1, 4, -1]), "rowgetter" ); 510 t.is( repr(rowgetter(['a', 'x', 'd'])(o)), repr([1, undefined, -1]), "rowgetter, nonexistent item" ); 511 502 512 };
