UNPKG

dojo

Version:

Dojo core is a powerful, lightweight library that makes common tasks quicker and easier. Animate elements, manipulate the DOM, and query with easy CSS syntax, all without sacrificing performance.

32 lines (30 loc) 804 B
define([], function(){ // module: // dojo/throttle // summary: // This module provide a throttler return function(cb, wait){ // summary: // Create a function that will only execute once per `wait` periods. // description: // Create a function that will only execute once per `wait` periods // from last execution when called repeatedly. Useful for preventing excessive // calculations in rapidly firing events, such as window.resize, node.mousemove // and so on. // cb: Function // The callback to fire. // wait: Integer // time to delay before allowing cb to call again. var canrun = true; return function(){ if(!canrun){ return; } canrun = false; cb.apply(this, arguments); setTimeout(function(){ canrun = true; }, wait); }; }; });