In JavaScript, you can use the Change Signature refactoring to:

On this page:

Examples

The following table shows 4 different ways of performing the same Change Signature refactoring.

In all the cases, the function result() is renamed to generate_result() and a new parameter input is added to this function.

The examples show how the function call, the calling function (show_result()) and other code fragments may be affected depending on the refactoring settings.

BeforeAfter
// This is the function whose signature will be changed:


function result() {
    // some code here
}

function show_result() {

    // Here is the function call:

    alert('Result: ' + result());
}

// Now we'll rename the function and
// add one (required) parameter.
// The function has been renamed to generate_result.
// The new parameter input has been added.

function generate_result(input) {
    // some code here
}

function show_result() {

    // The function call changed accordingly:

    alert('Result: ' + generate_result(100));
}

// When performing the refactoring, 100 was specified as
// the parameter value.
// This is the function whose signature will be changed:


function result() {

    // some code here
}

function show_result() {

    // Here is the function call:

    alert('Result: ' + result());
}

// Now we'll rename the function and add one parameter.
// This time, we'll specify that the parameter is optional.
// The function has been renamed to generate_result.
// The new optional parameter input has been added.

function generate_result(input) {
    input = input || 100;
    // some code here
}

function show_result() {

    // The function call changed accordingly:

    alert('Result: ' + generate_result(100));
}

// When performing the refactoring, 100 was specified as
// the parameter value.
// This is the function whose signature will be changed:


function result() {
    // some code here
}

// This function will also change its signature:

function show_result() {

    // Here is the function call:

    alert('Result: ' + result());
}

// Now we'll rename the function and add one required
// parameter. We'll also ask PyCharm to propagate
// the new parameter through the calling function show_result()
// to the function call.
// The function has been renamed to generate_result.
// The new parameter input has been added.

function generate_result(input) {
    // some code here
}

// Note the new function parameter:

function show_result(input) {

    // The function call changed accordingly:

    alert('Result: ' + generate_result(input));
}
// This is the function whose signature will be changed:


function result() {

    // some code here
}

// This function will also change its signature:

function show_result() {


    // Here is the function call:

    alert('Result: ' + result());
}

// Now we'll rename the function and add one optional
// parameter. We'll also ask PyCharm to propagate
// the new parameter through the calling function show_result()
// to the function call.
// The function has been renamed to generate_result.
// The new optional parameter input has been added.

function generate_result(input) {
    input = input || 100;
    // some code here
}

// Note the new function parameter:

function show_result(input) {
    input = input || 100;

    // The function call changed accordingly:

    alert('Result: ' + generate_result(input));
}

// When performing the refactoring, 100 was specified as
// the parameter value.
  1. In the editor, place the cursor within the name of the function whose signature you want to change.
  2. Do one of the following:
    • Press Ctrl+F6.
    • Choose Refactor | Change Signature in the main menu.
    • Select Refactor | Change Signature from the context menu.
  3. In the Change Signature dialog, make the necessary changes to the function signature and specify which other, related changes are required.

    You can:

  4. To perform the refactoring right away, click Refactor.

    To see the expected changes and make the necessary adjustments prior to actually performing the refactoring, click Preview.

See Also

Reference:

Web Resources: