Difference between setTimeout with and without quotes and parentheses

Using setInterval or setTimeout You should pass a reference to a function as the first argument for setTimeout or setInterval. This reference may be in the form of: An anonymous function setTimeout(function(){/* Look mah! No name! */},2000); A name of an existing function function foo(){…} setTimeout(foo, 2000); A variable that points to an existing function … Read more

TypeScript – use correct version of setTimeout (node vs window)

let timer: ReturnType<typeof setTimeout> = setTimeout(() => { … }); clearTimeout(timer); By using ReturnType<fn> you are getting independence from platform. You won’t be forced to use neither any nor window.setTimeout which will break if you run the code on nodeJS server (eg. server-side rendered page). Good news, this is also compatible with Deno!

Pass correct “this” context to setTimeout callback?

EDIT: In summary, back in 2010 when this question was asked the most common way to solve this problem was to save a reference to the context where the setTimeout function call is made, because setTimeout executes the function with this pointing to the global object: var that = this; if (this.options.destroyOnHide) { setTimeout(function(){ that.tip.destroy() … Read more

Combination of async function + await + setTimeout

Your sleep function does not work because setTimeout does not (yet?) return a promise that could be awaited. You will need to promisify it manually: function timeout(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function sleep(fn, …args) { await timeout(3000); return fn(…args); } Btw, to slow down your loop you probably don’t want … Read more

How can I pass a parameter to a setTimeout() callback?

setTimeout(function() { postinsql(topicId); }, 4000) You need to feed an anonymous function as a parameter instead of a string, the latter method shouldn’t even work per the ECMAScript specification but browsers are just lenient. This is the proper solution, don’t ever rely on passing a string as a ‘function’ when using setTimeout() or setInterval(), it’s … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)