You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by "Aditya Sharma (Jira)" <ji...@apache.org> on 2019/11/03 07:25:00 UTC
[jira] [Updated] (ROL-2157) Variables should be declared explicitly
in Custom JS code
[ https://issues.apache.org/jira/browse/ROL-2157?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Aditya Sharma updated ROL-2157:
-------------------------------
Issue Type: Bug (was: Improvement)
> Variables should be declared explicitly in Custom JS code
> ---------------------------------------------------------
>
> Key: ROL-2157
> URL: https://issues.apache.org/jira/browse/ROL-2157
> Project: Apache Roller
> Issue Type: Bug
> Reporter: Aditya Sharma
> Assignee: Aditya Sharma
> Priority: Major
>
> Pattern is identified and reported at sonacloud.io as Blocker
> JavaScript variable scope can be particularly difficult to understand and get right. The situation gets even worse when you consider the _accidental_ creation of global variables, which is what happens when you declare a variable inside a function or the {{for}} clause of a for-loop without using the {{let}}, {{const}} or {{var}} keywords.
> {{let}} and {{const}} were introduced in ECMAScript 2015, and are now the preferred keywords for variable declaration.
> Noncompliant Code Example
>
> {code:java}
> function f(){
> i = 1; // Noncompliant; i is global
> for (j = 0; j < array.length; j++) { // Noncompliant; j is global now too
> // ...
> }
> }
> {code}
>
> Compliant Solution
>
> {code:java}
> function f(){
> var i = 1;
> for (let j = 0; j < array.length; j++) {
> // ...
> }
> }
> {code}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)