Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsJavascript Editor Type Validation
https://www.eclipse.org/forums/index.php/mv/msg/207855/665843/#msg_665843
Unfortunately it doesn't seem to handle the 'new' keyword very well.
If I have the following in the included file:
function foo(){};
the following validates (and I can even ctrl-click to the definition in the other file):
var v = foo();
However if I do this:
var v = new foo();
The editor gives a 'foo cannot be resolved to type' error (I have 'check for unresolved types/fields' enabled for javascript validation).
(the above is legit javascript and it validates fine if I have the definition of 'foo()' in the same file)
My question is: Is this just too much to expect from the editor or is this a bug? Or maybe there is some setting I am missing?
Thanks in advance for any answers.
]]>Matt Taylor2011-04-16T23:46:02-00:00Re: Javascript Editor Type Validation
https://www.eclipse.org/forums/index.php/mv/msg/207855/665865/#msg_665865
This is not a bug, this is the way the JavaScript type inferencing is currently designed. The two most common ways we determine if something is a type is if we detect the following syntax:
function foo() {
this.bar = "test" <----the reference to 'this' tips us off this is a type and not just a function
}
function foo() {}
foo.prototype.myFunc = function() {} <-- the use of prototype tips us off this is a type.
Just having 'function foo() {}' just looks like a function to us and there is no information there hinting this could be a type.
My suggestion to you, if you do not want to see the validation message any more, would be to use one of the two syntaxes above or turn off the validation.
If you have any other further questions please do not hesitate to ask.
Blue Skies,
~Ian]]>Ian Tewksbury2011-04-17T13:59:42-00:00Re: Javascript Editor Type Validation
https://www.eclipse.org/forums/index.php/mv/msg/207855/666071/#msg_666071
I'm using the slightly condensed
foo.prototype.foo = {}
form and it works like a champ (it isn't exactly meaningful/correct javascript, but it is enough to tell the validator that foo is a type, which is good enough for a stub that will never see the light of a browser ).