Echo JS 0.11.0

<~>

amitport 2441 days ago. link 5 points
appreciate the effort, but this is really not that useful IMHO.

1 - setInterval is very well known and there should be a real compelling reason to use a custom wrapper api.

2 - the library usage has side-effects... if two dependencies/files use this without coping the instance- things will get unpredictable


3 - you're making SetInterval instances via object copy (prototype design pattern)- the created cloned instance is a new variable, which is what you set out to avoid.
3* - if you prefer objects over the interval return variable, it would have been simpler to use classes (though I still prefer the base API):

class Interval {
  constructor(fn, interval) {
    this.timer = setInterval(fn, interval);
  }
  clear() {clearInterval(this.timer);}
}
shystruk 2262 days ago. link 0 point
1. the reason is simple. You may clear the interval wherever you want in your application
2. you do not need to copy an instance here as it is a module and runs only once. 
3. no difference here, object or class, module runs once, just  do not repeat interval "key_string" and you will be good ;)