+ 4

JS - assignement and setTimeout

I''ve a main file, where I wrote let my_var = my_function(my_param); my_function is a require from another file (its working) however, in this function, there is a setTimeout and the return is in this one. so when I log my_var, its "undefined" How can I do ? I really must use the setTimeout, I cannot do without

24th Oct 2018, 1:19 PM
NoxFly
NoxFly - avatar
9 Respuestas
+ 6
As tu fait un lien avec les 2 fichiers en utilisant HTML ?
24th Oct 2018, 2:04 PM
program
program - avatar
+ 3
Maybe "var" instead of "let", or something like "var my_var = return my_function(my_param);"?
24th Oct 2018, 3:40 PM
Mattéo
+ 3
$napdragon no xd, let is new form of var. you can use both
24th Oct 2018, 4:50 PM
NoxFly
NoxFly - avatar
+ 3
NoxFly ドリアン yes, but "let" keyword can't function on a device without ES6 whereas "var" functions on devices with all versions of ECMAScript
24th Oct 2018, 5:40 PM
Mattéo
+ 3
oh ok
24th Oct 2018, 6:51 PM
NoxFly
NoxFly - avatar
+ 2
why you need setTimeout ? did you have a certain task that need to be done first before execute certain function ? if it is try using promise
24th Oct 2018, 2:30 PM
Taste
Taste - avatar
+ 2
can i see the my_function code ?
24th Oct 2018, 6:54 PM
Taste
Taste - avatar
+ 1
set timeout are running asynchronously, that means it the program doesnt wait for it to finish before continuing you can change your waiting method with sleep or turn the function into promise
24th Oct 2018, 7:37 PM
Taste
Taste - avatar