+ 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
9 odpowiedzi
+ 6
As tu fait un lien avec les 2 fichiers en utilisant HTML ?
+ 3
Maybe "var" instead of "let", or something like "var my_var = return my_function(my_param);"?
+ 3
$napdragon no xd, let is new form of var. you can use both
+ 3
NoxFly ドリアン yes, but "let" keyword can't function on a device without ES6 whereas "var" functions on devices with all versions of ECMAScript
+ 3
oh ok
+ 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
+ 2
can i see the my_function code ?
+ 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