Variable scope in javascript module

alweiss nginx-forum at forum.nginx.org
Fri Oct 26 06:16:52 UTC 2018


Hi team !,
Regarding the sample here :
https://www.nginx.com/blog/batching-api-requests-nginx-plus-javascript-module/

I have an issue trying to use JS module : variable hoisting and global/local
scope doesn't behave as expected. When i try to reassign the resp variable
(as you do after declaring it), the value assigned in the done function is
not brought outside of the done function to the bacthAPI function.
So if resp is initialised with 0 and reassign as 1 in the done funtion, at
the end, resp would = 0.
I had a look to explanation here
https://www.sitepoint.com/demystifying-javascript-variable-scope-hoisting/
and seems to behave differently in nginx implementation of JS.

Would it be some OS settings outside of NGINX preventing this to work as it
should normally work with javascript ? Any dependency on an OS package ?

Thanks !
BR
Alex

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281699,281699#msg-281699



More information about the nginx mailing list