简体   繁体   English

Eclipse(或Intellij IDEA)的专业品质JavaScript重构插件是什么?

[英]What is professional quality JavaScript refactoring plugin for Eclipse (or Intellij IDEA)?

Today when I tried to do simple renaming refactor in JavaScript using intellij IDEA 10, I was shocked what it did. 今天当我尝试使用intellij IDEA 10在JavaScript中进行简单的重命名重构时,我感到非常震惊。 It renamed that Class attribute everywhere regardless the attribute belonged to that class or not! 无论属性属于该类,它都将重命名为Class属性! For example Baz.attr1 renamed to Baz.attribute1 , it also renamed Box.attr1 to Box.attribute1 . 例如, Baz.attr1重命名为Baz.attribute1 ,它还将Box.attr1Box.attr1Box.attribute1 Refactor Preview does not help here because there are hundreds of places in which the same attribute name is used under different situations like this.attr1 type of references. Refactor Preview在这里没有帮助,因为有数百个地方在不同的情况下使用相同的属性名称,例如this.attr1类型的引用。

Eclipse does not even have JavaScript rename refactoring. Eclipse甚至没有JavaScript重命名重构。

In additional to renaming I am looking to refactor a group of functions and move them to Object Literal notations such as 除了重命名之外,我希望重构一组函数并将它们移动到Object Literal符号​​,例如

function foo() {

}
function bar() {
}

refactor to : 重构:

var MyCompany.Baz = {
 foo: function() {
  },
 bar: function() {
 }

}

It should refactor all references to those function calls in all the files including HTML and JSP files like foo(); 它应该重构所有文件中对这些函数调用的所有引用,包括HTML和JSP文件,如foo(); changing to MyCompany.Baz.foo(); 改为MyCompany.Baz.foo();

There is no such thing in either IDE. IDE中没有这样的东西。

Is there high quality plugin available for JavaScript for Eclipse (prefer) or Intellij IDEA that would do the kinds refactorings of I am talking about? 是否有高质量的插件可用于Eclipse(更喜欢)或Intellij IDEA的JavaScript,它可以进行我正在讨论的各种重构?

I believe that the kind of rename refactoring that you want is not possible in a dynamic language. 我相信你想要的那种重命名重构在动态语言中是不可能的。

Let's say that you have your classes Baz and Box with the attr1 attribute. 假设您的班级BazBox具有attr1属性。

If we write something like: 如果我们写下这样的话:

var b;
if (someCondition) {
    b = createBox();
} else {
    b = createBaz();
}
b.attr1 = "value";

What should the refactoring program do? 重构程序应该做什么?

Given that the type of the variable is only known when the corresponding code is executed, and that this type can differ at each invocation of that code, the computer is unable to determine to which definition an invocation of the attribute 'attr1' should be linked to. 鉴于变量的类型仅在执行相应代码时才知道,并且该类型在每次调用该代码时可能不同,计算机无法确定属性“attr1”的调用应该链接到哪个定义至。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM