tags:

views:

102

answers:

4

Is there is any way/tool to detect the duplicated variables/methods names in the project JavaScript files?

+3  A: 

jsLint might help you

http://www.jslint.com/

rikh
A: 

JavaScript Lint can probably help:

http://javascriptlint.com/

richardtallent
+2  A: 

There is no such thing as duplicate names in Javascript. You will never get an error when re-declaring a name that already exists.

To avoid overwriting existing names in Javascript, good developers do at least one of these things:

1) Carefully keep their variables out of the global scope, usually adding all names needed for the app under just one or two globally-scoped objects.

// No 
var foo = 1;
var bar = 2;
var bas = 3;

// Yes
var MyApp = {
    foo:1,
    bar:2,
    bas:3
}

2) Check that a variable name does not yet exist before creating it.

// No
var MyObj = {};

// Yes
var MyObj = MyObj || {} // Use MyObj if it exists, else default to empty object.
Triptych
A: 

http://javascriptlint.com/

joe