Skip to content

Instantly share code, notes, and snippets.

@McSodbrenner
McSodbrenner / README.md
Last active September 29, 2021 18:51
Javascript: Exact Javascript Timeout

This is a more precise version of the native setTimeout(). It uses the same parameters as setTimeout, but adds a third parameter "resolution" which defines how often (in ms) to check for the time that passed.

// alert after 5 seconds with an inaccuracy of 20 milliseconds
var timeout = setExactTimeout(function(){
   alert('done');
}, 5000, 20);

// comment out to show "done"
clearExactTimeout(timeout);
@McSodbrenner
McSodbrenner / gist:6129318
Last active December 20, 2015 12:09
Javascript: Multi Parameter log function
var log = function() {
if (!console) return;
if (console.group && arguments.length > 1) console.group("Log");
$.each(arguments, function(key, value) {
if (typeof value === 'object') console.dir(value); else console.log(value);
});
if (console.group && arguments.length > 1) console.groupEnd();
};