@buzzin0609/iterable-object

0.0.1 • Public • Published

Iterable Object

Gives ordinary Javascript objects the super Symbol.iterator power of the future!

Install

From npm npm install --save-dev iterable-object

Or Yarn yarn add iterable-object

To start using IObject, import or require it into your project.

import IObject from 'iterable-object
or
const IObject = require('iterable-object')

Example Usage

an instance of IObject acts like any other object:

const obj = new IObject({
    foo: 'bar'
});

console.log(obj.foo);
//outputs 'bar

However, the magic happens when you use the instance of IObject in a for...of loop, introduced in ES 2015:

const obj = new IObject({
    foo: 'bar'
});

for (let entry of obj) {
	console.log(entry);
	//outputs { key: 'foo', value: 'bar' }
}

Using object destructuring you can get direct access to the entry:

const obj = new IObject({
    foo: 'bar'
});

for (let { key, value } of obj) {
	console.log(key); // 'foo'
	console.log(value); // 'bar'
}

Package Sidebar

Install

npm i @buzzin0609/iterable-object

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

4 kB

Total Files

7

Last publish

Collaborators

  • buzzin0609