- Introduce variable
Refactoring commands are available:
- in ReSharper | Refactor menu
- on the context menu of the editor
- on the Refactor This context menu
ReSharper distinguishes functions and variables. According to the type of the property that should be refactored, the process of renaming goes on in two possible ways.
To rename a function, written by you, defined in js module or a library one, follow the procedure steps in the Refactorings: Rename topic.
When you rename a variable, refactoring is performed without dialogs.
- Position the caret at the name of a variable.
Do one of the following:
- On the main menu, choose ReSharper | Refactor | Rename.
- Press F2.
- Press Ctrl+Shift+R and select Rename on the Refactor This context menu.
- The edited variable is placed in a red rectangle, all others in black dotted rectangles.
- Type a new name and press Enter to apply the changes.
Consider the following example:
As you are typing, all usages of the variable are being updated accordingly.
The Introduce variable refactoring allows to create a new local variable based on a selected expression. Before the refactoring is applied you are prompted to decide whether to replace all occurrences of the expression or the selected one.
The algorithm of introducing variable is almost the same as described in the Refactorings: Introduce variable topic.
Consider the example below:
ReSharper prompts you to decide whether to replace all occurrences or the selected one.
ReSharper replaces specified occurrences with the use of local variable.