Skip to content

Instantly share code, notes, and snippets.

@nathanhannig
Created August 22, 2017 21:18
Show Gist options
  • Select an option

  • Save nathanhannig/b4276956a2f56901947b31aa23d1ffa2 to your computer and use it in GitHub Desktop.

Select an option

Save nathanhannig/b4276956a2f56901947b31aa23d1ffa2 to your computer and use it in GitHub Desktop.

Revisions

  1. breakpoint25 created this gist Aug 22, 2017.
    24 changes: 24 additions & 0 deletions js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    const james = {
    name: 'James',
    height: `5'10"`,
    weight: 185,
    [Symbol.iterator]: function() {
    const object = this;
    const keys = Object.keys(object);
    let index = 0;

    return {
    next: () => {
    const key = keys[index];
    index++;
    return { value: object[key], key: key, done: !(index < keys.length) };
    }
    };
    }
    };

    let iterator = james[Symbol.iterator]();

    console.log(iterator.next().value); // 'James'
    console.log(iterator.next().value); // `5'10`
    console.log(iterator.next().value); // 185