title: Decorators in javascript
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function debounce(f, ms) {
    let isCool = false;
  
    return function() {
      if (!isCool) {
        f.apply(this, arguments);
      }
      isCool = true;
      setTimeout(() =&gt; isCool = false, ms);
    };
  }
  
  
  let f = debounce(alert, 1000);
  
  f(1); // runs immediately
  f(2); // ignored
  
  
  setTimeout(() =&gt; f(3), 100); // ignored ( only 100 ms passed )
  setTimeout(() =&gt; f(4), 1100); // runs
  setTimeout(() =&gt; f(5), 1500); // ignored (less than 1000 ms from the last run)</code></pre>
  </div>
  </div>
  </p>
  
  <p>The result of debounce(f, ms) decorator should be a wrapper that passes the call to f at maximum once per ms milliseconds. When we call a “debounced” function, it guarantees that all future calls to the function made less than ms milliseconds after the previous call will be ignored. 
    Why my code doesn't working as it should be? It should ignore call to f(5), instead it runs...</p>