Last active
April 16, 2020 15:41
-
-
Save adefirmanf/19b2bc6ae4a9474598aec0be2f41fb57 to your computer and use it in GitHub Desktop.
Symbol.Iterator
This file contains 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
Number = new Proxy(Number, { | |
construct(target, args){ | |
let index = 0 | |
return { | |
[Symbol.iterator]() { | |
return this; | |
}, | |
next(){ | |
let value = args[0].toString() | |
if(index < value.length){ | |
index++; | |
return { | |
value : value[index - 1] | |
} | |
} | |
else{ | |
return { | |
a : undefined, | |
done : true | |
} | |
} | |
} | |
} | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment