Details
-
Type:
New Feature
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: JavaScript
-
Labels:None
-
Number of attachments :
Description
function fun() {
function nested() {
x = 42; // which 'x' - local or outer?
}
nested();
print(x); // 42
}
if local, then code should be rewritten as:
function fun() {
var x;
function nested() {
var x = 42;
}
nested();
print(x);
}
if outer, then:
function fun() {
var x;
function nested() {
x = 42;
}
nested();
print(x);
}
See http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone=var#var
Issue Links
- depends upon
-
SONARPLUGINS-2541
Symbol table
-
-
SONARPLUGINS-1788
Provide JavaScript rule engine based on SSLR
-
Activity
Evgeny Mandrikov
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Link |
This issue depends upon |
Evgeny Mandrikov
made changes -
| Summary | Rule: always use "var" for declarations | Rule: Always use "var" for declarations |
Evgeny Mandrikov
made changes -
| Assignee | Evgeny Mandrikov [ godin ] |
Evgeny Mandrikov
made changes -
| Link | This issue depends upon SONARPLUGINS-2541 [ SONARPLUGINS-2541 ] |
Evgeny Mandrikov
made changes -
| Description |
{noformat}
function fun() { x = 42; } fun(); print(x); // 42 {noformat} See http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone=var#var |
Evgeny Mandrikov
made changes -
| Description |
{noformat}
function fun() { x = 42; } fun(); print(x); // 42 {noformat} See http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone=var#var |
{noformat}
function fun() { x = 42; var y = 42; } fun(); print(x); // 42 print(y); // y is not defined {noformat} See http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone=var#var |
Evgeny Mandrikov
made changes -
| Description |
{noformat}
function fun() { x = 42; var y = 42; } fun(); print(x); // 42 print(y); // y is not defined {noformat} See http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone=var#var |
{noformat}
x = 13; function fun() { x = 42; var y = 42; } fun(); print(x); // 42 print(y); // y is not defined {noformat} See http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone=var#var |
Evgeny Mandrikov
made changes -
| Summary | Rule: Always use "var" for declarations | Rule: Always use "var" for variable declarations |
Evgeny Mandrikov
made changes -
| Fix Version/s | JAVASCRIPT-1.3 [ 19052 ] |
Evgeny Mandrikov
made changes -
| Description |
{noformat}
x = 13; function fun() { x = 42; var y = 42; } fun(); print(x); // 42 print(y); // y is not defined {noformat} See http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone=var#var |
{noformat}
function fun() { function nested() { x = 42; // which 'x' - local or outer? } nested(); print(x); // 42 } {noformat} if local, then code should be rewritten as: {noformat} function fun() { var x; function nested() { var x = 42; } nested(); print(x); } {noformat} if outer, then: {noformat} function fun() { var x; function nested() { x = 42; } nested(); print(x); } {noformat} See http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone=var#var |
Evgeny Mandrikov
made changes -
| Fix Version/s | JAVASCRIPT-1.3 [ 19052 ] |
Evgeny Mandrikov
made changes -
| Fix Version/s | JAVASCRIPT-1.3 [ 19052 ] |
Evgeny Mandrikov
made changes -
| Fix Version/s | JAVASCRIPT-1.3 [ 19052 ] |