在 Zend Studio (Eclipse PDT) 中跨多个文件扩展的单个 JavaScript 对象的自动完成

发布于 2024-11-14 18:57:01 字数 759 浏览 3 评论 0原文

我的 IDE 是 Zend Studio 8,它具有相对基本的 JavaScript 视角(即使不相同,也与 Eclipse PDT 中的视角类似)。在我正在开发的应用程序中,我们跨多个文件扩展了一个基本对象,这实际上消除了自动完成功能。请参阅下面的示例场景...

// global.js
var App = {
    objectA: {
        method1: function() {},
        method2: function() {}
    },
    objectB: {
        method1: function() {},
        method2: function() {}
    }
};

// extend.js
App.Extend = {
    anotherMethod: function() {}
};

在此场景中,输入 App. 会导致自动完成显示 objectAobjectB,但不显示 扩展。如果我将 Extend 添加到 global.js 中的 App 变量,它将出现在自动完成中,但不会出现在 anotherMethod 中。如果我使用 var Extend = { /* code */ };,自动完成功能将适用于 Extend 对象,因此问题似乎与事实上,代码跨多个文件扩展。也许是因为单个对象分布在多个文件中......或者其他原因。

有人有什么想法吗?

My IDE is Zend Studio 8, which features a relatively basic perspective for JavaScript (similar to, if not the same as, the perspective in Eclipse PDT). In the application I'm working on, we extend a base object across multiple files, which has effectively killed the autocomplete functionality. See below for an example scenario...

// global.js
var App = {
    objectA: {
        method1: function() {},
        method2: function() {}
    },
    objectB: {
        method1: function() {},
        method2: function() {}
    }
};

// extend.js
App.Extend = {
    anotherMethod: function() {}
};

In this scenario, typing App. causes autocomplete to appear with objectA and objectB, but not Extend. If I add Extend to the App variable in global.js, it will appear in the autocomplete, but not with anotherMethod. If I were to use var Extend = { /* code */ };, autocomplete would work for the Extend object, so the problem does not seem to be related to the fact that the code is extended across multiple files. Perhaps it is because a single object is being spread across multiple files...or something else.

Anyone have any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

内心激荡 2024-11-21 18:57:01

由于 Javascript 不是编译语言,因此 IDE 不知道扩展类在哪里。一些高级 IDE 尝试通过将每个 javascript 文件视为单个项目的一部分来解决此问题,从而在后台将它们组合起来以提供自动完成功能。

我使用过各种 IDE,我见过的唯一可以使用它的 IDE 是 Jetbrain 的 Webstorm

Since Javascript is not a compiled language, the IDE has no idea where your extended classes are. Some advanced IDEs try to workaround this by considering every javascript file to be part of single project and thus, combining them in the background to give you autocomplete.

I've played with a variety of IDEs and the only IDE I've seen it work from is Jetbrain's Webstorm

爱格式化 2024-11-21 18:57:01

VJET JS IDE for Eclipse 有一种使用 vjetdoc 语法跨多个文件扩展的方法。看看 - http://www.ebayopensource.org/wiki/display/VJET/JS+code+assist+and+validation+for+two+or+more+js+files

它适用于对象文字、变量、功能。一旦您了解类概念,通常就会有一个包装函数来定义类。在VJET中有vjo.ctype,它允许您在js中创建类。 VJET 为使用此类构建套件定义的类提供正确的支持。这是一个例子:

Base.js
vjo.ctype("namespace.Base")
.endType();

App.js
vjo.ctype("namespace.App")
.inherits("namespace.Base")
.protos({
   doIt:function(){}
})
.endType()

VJET JS IDE for Eclipse has a way of extending across multiple files using a vjetdoc syntax. Check it out -- http://www.ebayopensource.org/wiki/display/VJET/JS+code+assist+and+validation+for+two+or+more+js+files

It works with object literal, variables, functions. As soon as you go to class concepts there is typically a wrapper function to define classes. In VJET there is vjo.ctype which allows you to create classes in js. VJET provides correct assist for classes defined with this type construction kit. Here is an example:

Base.js
vjo.ctype("namespace.Base")
.endType();

App.js
vjo.ctype("namespace.App")
.inherits("namespace.Base")
.protos({
   doIt:function(){}
})
.endType()
甜味超标? 2024-11-21 18:57:01

不熟悉 Zend Studio,但从你的说法来看,尚不清楚它是否仅适用于全局变量。也就是说,如果我理解正确的话,这是有效的:

// global.js
var App = {
    objectA: {
        method1: function() {},
        method2: function() {}
    },
    objectB: {
        method1: function() {},
        method2: function() {}
    }
};

// extend.js
var Extend = {
    anotherMethod: function() {}
};

但是,如果你添加这个,这会有效吗?

// extend.js
...
var More = {
    streetWithNoName: false,
};
More.helloWorld = [1, 2, 3]

如果您无法在 More. 上获得 helloWorld 的自动完成功能(并且由于它在 Extend 上工作,您应该获得 HelloWorld 的自动完成功能) code>streetWithNoName),那么 Zend 可能没有执行非全局完成,我想无论如何这是一件非常困难的事情。如果可以,那么您始终可以这样做:

var innerAppExtend = App.Extend = { ... };

作为一种解决方法,当然,如果您可以接受的话。

Not familiar with Zend Studio, but from what you say it is not clear whether it works on globals only or not. I.e. if I understood you correctly, this works:

// global.js
var App = {
    objectA: {
        method1: function() {},
        method2: function() {}
    },
    objectB: {
        method1: function() {},
        method2: function() {}
    }
};

// extend.js
var Extend = {
    anotherMethod: function() {}
};

However, if you add this, will this work?

// extend.js
...
var More = {
    streetWithNoName: false,
};
More.helloWorld = [1, 2, 3]

If you cannot get auto-complete for helloWorld on More. (and as it works on Extend, you should get the auto-complete for streetWithNoName), then probably Zend is not doing a non-global completion, which I guess is a very hard thing to do anyway. If it can, then you can always do:

var innerAppExtend = App.Extend = { ... };

as a workaround, if that's acceptable to you of course.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文