diff --git a/source/Ox/js/Collection.js b/source/Ox/js/Collection.js index d5217027..2354f97b 100644 --- a/source/Ox/js/Collection.js +++ b/source/Ox/js/Collection.js @@ -28,7 +28,7 @@ Ox.contains Tests if a collection contains a value @*/ Ox.contains = function(col, val) { /* - // fixme: rename to Ox.has or Ox.isIn? + // fixme: rename to Ox.has or Ox.in? // then it'd become convenient for arrays */ return (Ox.isObject(col) ? Ox.values(col) : col).indexOf(val) > -1; @@ -45,7 +45,6 @@ Ox.copy Returns a (shallow or deep) copy of an object or array @*/ Ox.copy = Ox.clone = function(col, deep) { // fixme: copy or clone? - // fixme: is there any use case for shallow copy? var ret = Ox.isArray(col) ? [] : {}; if (deep) { Ox.forEach(col, function(val, key) { @@ -150,8 +149,8 @@ Ox.forEach forEach loop Returning false from the iterator function acts like a break statement (unlike [].forEach(), like $.each()). The arguments of the iterator function are - (value, key) (like [].forEach(), unlike - $.each()). + (value, key, index) (more like [].forEach() + than like $.each()). (collection, callback) The collection (collection, callback, includePrototype) The collection collection An array, object or string @@ -210,6 +209,7 @@ Ox.getIndexById Returns the first array index of an object with a given id 0 @*/ Ox.getIndexById = function(arr, id) { + // FIXME: shouldn't this be merged into Ox.getIndex? return Ox.getIndex(arr, 'id', id); }; @@ -239,6 +239,7 @@ Ox.getObjectById Returns the first object in an array with a given id {id: "foo", str: "Foo"} @*/ Ox.getObjectById = function(arr, id) { + // FIXME: shouldn't this be merged into Ox.getObject? return Ox.getObject(arr, 'id', id); }; @@ -324,7 +325,7 @@ Ox.isEmpty Returns true if a collection is empty false @*/ Ox.isEmpty = function(val) { - return Ox.len(val) == 0; + return Ox.len(val) === 0; }; /*@ @@ -480,6 +481,7 @@ Ox.map = function(obj, fn) { var isObject = Ox.isObject(obj), ret = isObject ? {} : []; Ox.forEach(obj, function(val, key) { + // FIXME: is there any reason for this strange assignment? var map; if ((map = fn(val, key)) !== null) { ret[isObject ? key : ret.length] = map; @@ -644,14 +646,14 @@ Ox.sum = function(col) { return sum; }; -Ox.toArray = function(obj) { - // fixme: can this be thrown out? - /* +/*@ +Ox.toArray Wraps any non-array in an array. >>> Ox.toArray('foo') ['foo'] >>> Ox.toArray(['foo']) ['foo'] - */ +@*/ +Ox.toArray = function(obj) { var arr; if (Ox.isArray(obj)) { arr = obj; @@ -684,7 +686,7 @@ Ox.values = function(col) { }; /*@ -Ox.walk Recursively walk a tree-like key/value store +Ox.walk Recursively walk a tree of key/value pairs