Last active
September 8, 2017 16:57
-
-
Save Woodsphreaker/8e58e4c6a14c27fdd1c4dfcdddb0bfb9 to your computer and use it in GitHub Desktop.
intervalClosure
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
| const interval = (id, time = 1000) => { | |
| const el = [] | |
| const start = () => { | |
| el[id] = setInterval(() => { | |
| console.log(`${new Date().toLocaleTimeString()} Identificador ${id}\n`) | |
| }, time) | |
| } | |
| const stop = () => { | |
| clearInterval(el[id]) | |
| } | |
| return { | |
| start, | |
| stop | |
| } | |
| } | |
| const newIterval1 = interval("id1") | |
| const newIterval2 = interval("id2", 500) | |
| const newIterval3 = interval("id3", 800) | |
| newIterval1.start() | |
| newIterval2.start() | |
| newIterval3.start() | |
| setTimeout(() => newIterval1.stop(), 5000) | |
| setTimeout(() => newIterval2.stop(), 5000) | |
| setTimeout(() => newIterval3.stop(), 10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment