Code Completion — Aptana Eclipse Plugin

天涯浪子 提交于 2019-12-06 03:46:34
pagga

Hopefully I can help answer all of your questions related to Aptana's code completion behavior. To encourage Aptana's code completion cooperation, I have been using this approach with success:

var foo = function(){
}
foo.prototype.a = "a"
foo.prototype.b = function(){ alert(this.a) }

You say

Also, I am not very successful in getting code completion to work across files.

but I've had good luck so far. However, I've found that if I have f = new foo() but change it to f = new bar(), code completion shows properties of plain ol' Object as opposed to either foo or bar. Renaming the variable (b = new bar() from f = new foo() ) or restarting the editor seems to help.

Any ideas what the difference is? Is the second a valid class in javascript?

About "new function()", according to `new function()` with lower case "f" in JavaScript , something like

var foo = new function(){ ... }

instead of

var foo = { ... } // JSON style

or

var foo = function(){ ... }

is part of a workaround to implementing private access of properties. Keep in mind through all of this that there are no "classes" in JS, but rather Objects. Everything is an object.

Does anyone know why Aptana works for the last [JSON] style, but not the first?

The JSON style declaration actually creates instance of an Object named foo, so Aptana has no issue looking it up. Using a function allows separate instances, as you mention, but Aptana seems not to track properties of things that are declared as functions until prototype is found. My reasoning is, prototype triggers Aptana's code completion because every instance of the custom object will have all the properties specified. Without prototype, properties must be re-defined for each instance (generally done in the constructor function, but note in my top most code block my constructor is empty because I use prototype to define the custom object). This link explains more about prototype in this context http://www.phpied.com/3-ways-to-define-a-javascript-class/

What is your default JavaScript Editor in Aptana (under Windows > Preferences > File Associations > *.js)? I use the Aptana JS Editor and not the JavaScript Editor (default by installation). Note that these settings can be different per project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!