Last Updated: February 25, 2016
·
536
· aintaer

Leaky Functional Bucket

To combine multiple calls to one function into one call (after all others are finished), use setTimeout to break out of the current call stack!

function collector() {
  collector._count = collector._count || 0;
  if (!collector._count) {
    setTimeout(function() {
      target();
      collector._count=0;
    }, 0);
  }
  collector._count++;
}

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#javascript
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside