Welcome! Log In Create A New Profile

Advanced

Re: Variable scope in javascript module

Dmitry Volyntsev
October 26, 2018 05:04AM
Hi Alex,

Can you, please, share your code?

You can also try to play with njs code in the command line interface.

For example:

njs
interactive njs 0.2.3

v.<Tab> -> the properties and prototype methods of v.
type console.help() for more information

>>function my(){var g = 'init'; console.log(g); (function() {g = 'anon'})(); console.log(g) }; my()
'init'
'anon'
undefined

CLI, is also available in docker
docker run -i -t nginx:latest /usr/bin/njs



> On 26 Oct 2018, at 09:16, alweiss <nginx-forum@forum.nginx.org> wrote:
>
> 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
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Variable scope in javascript module

alweiss October 26, 2018 02:16AM

Re: Variable scope in javascript module

Dmitry Volyntsev October 26, 2018 05:04AM

Re: Variable scope in javascript module

alweiss October 30, 2018 12:07PM

Re: Variable scope in javascript module

alweiss October 30, 2018 12:58PM

Re: Variable scope in javascript module

Dmitry Volyntsev October 30, 2018 01:10PM

Re: Variable scope in javascript module

Valentin V. Bartenev October 30, 2018 01:12PM

Re: Variable scope in javascript module

alweiss October 30, 2018 05:55PM

Re: Variable scope in javascript module

Valentin V. Bartenev October 30, 2018 06:28PM

Re: Variable scope in javascript module

Maxim Konovalov October 30, 2018 06:32PM

Re: Variable scope in javascript module

alweiss October 30, 2018 07:22PM

Re: Variable scope in javascript module

alweiss October 30, 2018 06:47PM

Re: Variable scope in javascript module

Valentin V. Bartenev October 30, 2018 07:58PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 65
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready