minor changes in Collection.js, mostly documentation
This commit is contained in:
parent
4b59c9a2a9
commit
9265efe61a
1 changed files with 12 additions and 10 deletions
|
@ -28,7 +28,7 @@ Ox.contains <f> 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 <f> 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 <f> forEach loop
|
|||
Returning <code>false</code> from the iterator function acts like a
|
||||
<code>break</code> statement (unlike <code>[].forEach()</code>, like
|
||||
<code>$.each()</code>). The arguments of the iterator function are
|
||||
<code>(value, key)</code> (like <code>[].forEach()</code>, unlike
|
||||
<code>$.each()</code>).
|
||||
<code>(value, key, index)</code> (more like <code>[].forEach()</code>
|
||||
than like <code>$.each()</code>).
|
||||
(collection, callback) <a|o|s> The collection
|
||||
(collection, callback, includePrototype) <a|o|s> The collection
|
||||
collection <a|o|s> An array, object or string
|
||||
|
@ -210,6 +209,7 @@ Ox.getIndexById <f> 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 <f> 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 <f> 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 <f> 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 <f> Recursively walk a tree-like key/value store
|
||||
Ox.walk <f> Recursively walk a tree of key/value pairs
|
||||
<script>
|
||||
Ox.test.number = 0;
|
||||
Ox.walk({a: 1, b: {c: 2, d: 3}}, function (v) {
|
||||
|
|
Loading…
Reference in a new issue