• TypeError: redeclaration of const

    From Mortifis@VERT/ALLEYCAT to All on Mon Aug 19 07:58:07 2019
    I have an xjs/ssjs script that, when called once works as expected, but whenãcalled a second time I get:ããTypeError: redeclaration of constããIf I wait a few minutes and run the script again it works as expected thenãcraps out. Is this a web browser issue? I tried setting the const(s) toãundefined and then delete(const) but that did not resolve the redeclarationãissue.ããAny ideas?ãããMy doctor said I have the body of a 25 year old ... and the mind of a 10 :-/ãã---ã þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81ã
  • From echicken@VERT/ECBBS to Mortifis on Mon Aug 19 09:18:00 2019
    Re: TypeError: redeclaration of constã By: Mortifis to All on Mon Aug 19 2019 07:58:07ãã Mo> I have an xjs/ssjs script that, when called once works as expected, but whenã Mo> called a second time I get:ãã Mo> TypeError: redeclaration of constãã Mo> If I wait a few minutes and run the script again it works as expected thenã Mo> craps out. Is this a web browser issue? I tried setting the const(s) toã Mo> undefined and then delete(const) but that did not resolve the redeclarationã Mo> issue.ããThe Synchronet webserver reuses the same JS context across multiple requests from the same client. It can take a few minutes for the client's session to expire and a new context to be created. So basically you may end up reusing the same global scope across multiple executions of a script.ããSo using 'const' at the *top level* of an XJS/SSJS script is inadvisable. Use 'var' instead.ããIt's okay to use 'const' inside of functions.ããIt's probably also okay to wrap your entire script in an IIFE so that you get a fresh scope for each request. However, this context reuse was done for performance reasons, so you'd be sacrificing any performance gain by doing that.ãã(function () {ã // This is an IIFEã // It's an Immediately Invoked Function Expressionã})();ãã---ãechickenãelectronic chicken bbs - bbs.electronicchicken.comã þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.comã
  • From Mortifis@VERT/ALLEYCAT to echicken on Mon Aug 19 12:34:18 2019
    ã > The Synchronet webserver reuses the same JS context across multiple requestsã > from the same client. It can take a few minutes for the client's session toã > expire and a new context to be created. So basically you may end up reusingã > the same global scope across multiple executions of a script.ãã > So using 'const' at the *top level* of an XJS/SSJS script is inadvisable.ã > Use 'var' instead.ãã > It's okay to use 'const' inside of functions.ãã > It's probably also okay to wrap your entire script in an IIFE so that youã > get a fresh scope for each request. However, this context reuse was doneã > for performance reasons, so you'd be sacrificing any performance gain byã > doing that.ãã > (function () {ã > // This is an IIFEã > // It's an Immediately Invoked Function Expressionã > })();ãããExcellent, thank you!ãããMy doctor said I have the body of a 25 year old ... and the mind of a 10 :-/ãã---ã þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81ã