Created
August 20, 2020 19:08
-
-
Save patridge/fbdb0114c1cf10c8880fa8abd3ee15fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// e.g., inject something whenever iterating a list | |
const arr = [ 1, 2, 3 ]; | |
arr[Symbol.iterator] = function () { | |
let i = 0; | |
let arr = this; | |
return { | |
next: function () { | |
if (i >= arr.length) { | |
return { done: true }; | |
} else { | |
const value = arr[i] + "🎵"; | |
i++; | |
return { value, done: false }; | |
} | |
} | |
}; | |
}; | |
for (const x of arr) { console.log(x); } // => 1🎵\n2🎵\n3🎵 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment