You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pagespeed.apache.org by GitBox <gi...@apache.org> on 2019/05/15 06:26:59 UTC

[GitHub] [incubator-pagespeed-mod] theartofweb opened a new issue #1887: 'const' variables in eval'ed code

theartofweb opened a new issue #1887: 'const' variables in eval'ed code
URL: https://github.com/apache/incubator-pagespeed-mod/issues/1887
 
 
   If you have a global JavaScript variable/function in an external JS file:
   
   `const checkForm = function(form) { ... };`
   
   then ModPageSpeed wraps it into an eval statement:
   
   `var mod_pagespeed_EBwFaDOlRN = "const checkForm=function(e){...};"`
   
   `<script>eval(mod_pagespeed_EBwFaDOlRN);</script>`
   
   but when the page loads, 'checkForm(form)' is no longer a global function.
   
   The workaround is to keep using "var" instead of "const" for functions and variables that need to stay global, and "const" only within classes or functions.
   
   This is a known issue when combining "const" with "eval": https://stackoverflow.com/a/50099981
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services