Guest User

Untitled

a guest
Nov 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. const someObject = {
  2. a: 1,
  3. perrito: 'Yolodog',
  4. aChar: 'a',
  5. }
  6.  
  7. someObject[Symbol.iterator] = function() {
  8. let currentKey = 0;
  9. const keys = Object.keys(this);
  10. const { length } = keys;
  11. return {
  12. next: function() {
  13. return currentKey < length
  14. ? { value: this[keys[currentKey++]], done: false }
  15. : { done: true };
  16. }.bind(this),
  17. };
  18. };
  19.  
  20. for (let item of someObject) { console.log(item); }
  21. // 1
  22. // Yolodog
  23. // a
Add Comment
Please, Sign In to add comment