This module exports utility functions.
- Source:
Methods
-
<static> bless(item, model) → {Object}
-
This makes an item as the model class's instance.
Parameters:
Name Type Description item
Object target item model
function model class (constructor) - Source:
Returns:
blessed item- Type
- Object
Example
var utils = KagoDB.bundle.utils; function Item() {} Item.prototype.NAME = function() { return this.name.toUpperCase(); }; var item = {name : 'ken'}; item = utils.bless(item, Item); console.log(item.name, item.NAME()); // => ken KEN
-
<static> clone(source) → {Object}
-
It creates a shallow-copied clone of the object. Any nested objects or arrays will be copied by reference, not duplicated.
Parameters:
Name Type Description source
Object source object - Source:
- See:
Returns:
cloned object- Type
- Object
Example
var utils = KagoDB.bundle.utils; var source = {name : 'moe'}; var clone = utils.extend(source); console.log(clone); // => {name : 'moe'}
-
<static> eachSeries(arr, iterator, callback)
-
It applies an iterator function to each item in an array in series. The next iterator is only called once the current one has completed processing. This means the iterator functions will complete in order.
Parameters:
Name Type Argument Description arr
Array an array to iterate over iterator
function function(item, next) {} callback
function <optional>
function(err) {} Example
var utils = KagoDB.bundle.utils; var arr = ['foo', 'bar', 'baz']; utils.eachSeries(arr, iterator, end); function iterator(item, next) { console.log(item); // do some thing next(); } function end(err){ console.error(err); }
-
<static> extend(dest, source) → {Object}
-
It copies all of the properties in the source objects over to the destination object.
Parameters:
Name Type Description dest
Object destination object source
Object source object - Source:
- See:
Returns:
destination object- Type
- Object
Example
var utils = KagoDB.bundle.utils; var dest = {name : 'moe'}; var source = {age : 50}; utils.extend(dest, source); console.log(dest); // => {name : 'moe', age : 50}
-
<static> inherits(child, parent) → {function}
-
It imports super class's instance methods to the child class inherited.
Parameters:
Name Type Argument Description child
function <optional>
constructor for child class parent
function <optional>
super class - Source:
- See:
Returns:
child class- Type
- function
Example
var utils = KagoDB.bundle.utils; function ParentClass() {} ParentClass.prototype.foo = function() { console.log('bar'); }; function ChildClass() {} utils.inherits(ChildClass, ParentClass); var child = new ChildClass(); child.foo(); // => 'bar'