2.1 KiB
2.1 KiB
object-iterators
The object iterators, similar in function to those found in underscore.js.
NOTE: As of v1.2.0, object-iterators is now a simple node module. It is no longer a "modified node module" (containing its own closure for use directly in a browser).
Synopsis
Node.js:
var Base = require('object-iterators').Base;
Browser:
<script src="http://joneit.github.io/object-iterators/object-iterators.min.js"></script>
Usage example:
var obj = {
id: 30,
name: 'Jack',
gender: 'male'
};
print(obj === _(obj).each(function(value, key) { print(key, value); }));
// id 30
// name Jack
// gender male
// true
print(_(obj).reduce(function(memo, value, key) { return memo + (parseInt(value) || 0); }, 100))
// 130
print(_(obj).find(function(value, key) { return value === 'Jack'; }));
// Jack
print(_(obj).find(function(value, key) { return value === 'Jill'; }));
// undefined
function print() { console.log('// ' + Array.prototype.slice.call(arguments).join(' ')); }
API documentation
Detailed API docs can be found here.
Demo
A demo can be found here.
Or see the Underscore docs:
Just keep in mind that these are for objects only (not arrays).
CDN versions
To use in a browser, you have two options:
- Incorporate the node module into your own browserified project.
- Use the browserified versions
object-iterators.js
orobject-iterators.min.js
available on the Github pages CDN.
Submodules
See the note Regarding submodules for important information on cloning this repo or re-purposing its build template.