Extract parameter
Refactor | Extract/Introduce | Parameter
CtrlAlt0P
The Extract Parameter refactoring is used to add a new parameter to a function declaration and to update the function calls accordingly.

note
By default, this extract refactoring will be applied in the editor via in-line controls. To change your settings to apply the refactoring via a modal, open the Settings dialog (CtrlAlt0S) , go to Editor | Code Editing, and in the Refactorings area select In modal dialogs.
In the editor, place the caret within the expression to be replaced by the parameter.
Do one of the following:
Press CtrlAlt0P.
Choose Refactor | Extract/Introduce | Parameter from the main menu.
Choose Refactor | Introduce Parameter from the context menu.
On the floating toolbar that appears when a code fragment is selected, click Extract and select Parameter.
If more than one expression is detected for the current caret position, the Expressions list appears. If this is the case, click the expression to select it. Alternatively, press Up or Down to navigate to the expression of interest, and then press Enter to select it.
Type the parameter name in the box with a red border.
To complete the refactoring, press Tab or Enter.
If you haven't completed the refactoring and want to cancel the changes you have made, press Esc.
Note that sometimes you may need to press the corresponding key more than once.
In the example below, a new parameter $c is added to the Calculate() function to replace 10:
Before | After |
---|---|
|
|
Before | After |
---|---|
A new parameter will be added to this function to replace the 1's:
| The new parameter i2 has been added as an optional parameter:
|
A new parameter will be added to this function to replace the 1's. When adding a new parameter we'll specify that it should be a required one.
| The new parameter i2 has been added as a required parameter:
|
For more information, refer to Extract Parameter in JavaScript.
Thanks for your feedback!