JavaScript Refactoring: Inline Variable

Posted on by Eugene Toporov

One of the major techniques to keep your code in a good shape is refactoring it. In the latest Web IDE EAP (#470) you can try the just added Inline Variable JavaScript refactoring.

Inline Variable — replaces local variable occurrences with its initializing expression.

Before

After

The Inline Variable refactoring, by the way, also works in the left part of local variable assignment.

During the inline process, Web IDE verifies if a variable can be safely replaced and gives a warning if not, e.g. there are its usages inside a functional expression.


More JS refactorings are coming in next builds.

Develop with pleasure!

Comments below can no longer be edited.

7 Responses to JavaScript Refactoring: Inline Variable

  1. Ilya says:

    October 6, 2009

    What is this color scheme and where take the same? 😉

  2. Eugene Toporov says:

    October 6, 2009

    This one is ‘Thinmint’ from here: http://www.jetbrains.net/devnet/docs/DOC-1154
    We are going to add a dark scheme to Web IDE in one of following builds

  3. Taras Tielkes says:

    October 6, 2009

    What about refactoring support for PHP?

  4. Alexey Gopachenko says:

    October 6, 2009

    Full set of refactorings is planned.

    Currently only “Rename” is implemented (for files, constants, functions, classes, members, parameters and variables).

  5. Taras Tielkes says:

    October 6, 2009

    Alexey, that’s exiting. “Introduce variable” and “Inline variable” are probably the most common ones.
    Do you plan to implement language injection in the first release? Obviously there are hundreds of candidates (literally) for injecting SQL language.

  6. Dean says:

    March 19, 2010

    By the way, that example of refactoring the get cookie function is actually worse than before in the inline variable example – in the “after” shot, the cookie length is evaluated at every iteration in the while loop, instead of just once in the before shot.

  7. Eugene Toporov says:

    March 19, 2010

    @Dean: thanks for the feedback. The example is given just to demonstrate the refactoring but not as a recommendation to refactor this particular code. We realize all developers know their code and make a right decision about the refactorings.