Support for JavaScript

For a long time, writing JavaScript code in Visual Studio was very painful. There were no tools that could support writing JavaScript. But ReSharper changed this by providing you with a rich set of features that you know from C#.

Tip

ReSharper supports JavaScript code, both written in separate files and inline in the same way.

Smart IntelliSense

Support for JavaScript starts with IntelliSense. IntelliSense prompts you with defined JavaScript keywords and methods, and objects and methods from your custom objects as well as from external JavaScript libraries such as jQuery. A sample prompt for jQuery methods is shown in the following screenshot:

Smart IntelliSense

Tip

In jQuery, selectors are very important as they allow you to access any HTML element. ReSharper can help you with specifying selectors by providing you with a list of available CSS classes and HTML tags.

The Code Analysis and refactoring options

Another well-known ReSharper feature is Code Analysis. It allows you to quickly find and fix some common errors.

From this analysis, ReSharper will notify you when it will find any one of the following conditions:

  • Unused or redundant code
  • Duplicate labels in the switch statement or property declaration
  • Statement not terminated with a semicolon
  • Possibly unassigned property or variable

You can find a complete list of available Code Inspections in the ReSharper options by navigating to Code Inspection | Inspection Severity in the JS tab.

Together with Code Analysis, ReSharper comes with some simple refactoring methods for JavaScript. You will find options such as Rename, Create from usage, or Introduce variable.

All these features work in JavaScript in the same way as they work in C#.

Navigation and smart usages

With ReSharper, you can also easily review JavaScript code structure in the File Structure window. A sample structure is shown in the following screenshot:

Navigation and smart usages

Same as in other languages, you can navigate between different type members in your file with the Go to File Member (Alt + ) option and find code dependencies by finding the code declaration or code usage.

Structural Search and Replace (SSR)

Starting with ReSharper v8, you can use the SSR feature together with JavaScript code. You can find out more about this feature in Chapter 4, Making Your Code Better.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.240.244