Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 99633

Summary: JavaScript object-oriented
Product: z_Archived Reporter: Martin Burchard <webtools>
Component: Webtools.WST.JavascriptAssignee: David Williams <david_williams>
Status: RESOLVED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3 CC: am, apeller, asqueella, bugs.eclipse.org, clement.idelon, juan.lanus, levik, pombredanne
Version: unspecifiedKeywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Martin Burchard CLA 2005-06-13 09:37:23 EDT
The JavaScript Editor seems to ignore everything in JavaScript that is written
object-oriented.

Example:

function person() {
  this.name = '';
  this.age = 0;
};

person.prototype.init = function(name, age) {
  this.name = name;
  this.age = age;
};

The Editor has no support for code completion when using own objects.
Also the outline can't handle such JavaScript objects.

This would be a nice feature because OO in Javascript is very powerfull.
Comment 1 David Williams CLA 2005-06-21 00:07:07 EDT
Martin, I agree -- and I think from your comments you'd agree this is more 
a "feature request" than a "bug" ... so I'm changing to enhancment severity. 
(please change back if you disagree).

Frankly, though, no one on core team could do this work, so am marking as 
"helpwanted". 
Comment 2 Lev Epshteyn CLA 2005-08-12 11:37:03 EDT
I'm wondering if the outline is currently built by parsing the .js file - since
Javascript is inherently runtime, one would probably need to interpret the code
(in the context of the entire project no less - what if it's pulling in classes
from other js files?) in order to arrive at meaningful results.

Other approaches would probably be nothing more than stop-gap fixes that will
not address the full plethora of JS coding styles out there.
Comment 3 Adam Peller CLA 2005-08-25 11:48:52 EDT
I think you could go a long way and satisfy many developers based on parsing for
patterns in the code, such as the one described (as the old sourceforge jseditor
did)  True, properties and methods could be defined at runtime, but they might
even change over the course of execution, so there would not truly be a static
outline to look at anyway -- if you want that, you really need a debugger!

The current parser is really a tokenizer and lacks an abstract syntax tree. 
Perhaps a stop-gap measure to recognize only the pattern shown below would be a
good first step?  Rendering "var" statements in the outline, regardless of
scope, seems to conflict with the propsed o-o outline view, and I propose that
it be disabled, or perhaps this could be controlled via preferences?
Comment 4 Joakim Kemeny CLA 2005-08-25 16:53:30 EDT
I don't think that this is impossible to achieve by using Rhino. I played 
around with this a little bit today, after seeing this bug today, to 
investigate if it would be possible to do and I think it is.

I'm not an Eclipse programmer so I don't know what is needed to integrate this 
into Eclipse but I managed to create a syntax tree for a set of JavaScript 
files and print it. It can detect fields and method of classes and check if 
they are static or not. If you follow the coding standard to let private 
fields and methods start with _ it can also detect this.

The only problem that I have right now is to detect which classes that exists 
(I used a predefined list of classes) but this can probably be found by using 
the methods of Rhino but I haven't found this yet. If anybody who knows more 
about Eclipse is interested, I can help with this feature.
Comment 5 Adam Peller CLA 2005-08-30 22:10:23 EDT
Yes, I thought about that approach also.  Rather than building a parser, you
could use Rhino as the parser and use its syntax tree.  I believe this is just a
compile phase and not a runtime phase, though.  You probably wouldn't want to
execute the code for performance reasons and it generally shouldn't be necessary
to do an eval?  Also, I'm not sure what the implications would be of including a
Rhino dependency in the current code.
Comment 6 Adam Peller CLA 2005-09-07 21:07:06 EDT
dup of #88902?
Comment 7 Lev Epshteyn CLA 2005-09-11 15:04:54 EDT
Just checked out the old SF.net jseditor (from
https://sourceforge.net/projects/jseditor/ )... It seems like that one does a
very decent job of detecting prototype assignments as OO constructs as Adam
said, but tends to fall short in most other aspects (code completion, etc). 

Given that (as the page claims) the torch was passed on to WTP, perhaps the
outline-building code could be stripped out of that plugin and brought over to
the new JS editor? 
Comment 8 Jens Ansorg CLA 2007-09-22 02:36:35 EDT
*** Bug 204349 has been marked as a duplicate of this bug. ***
Comment 9 David Williams CLA 2007-12-17 01:59:10 EST
I'm doing a mass resolve of all open bugs in the wst.javascript component. 
Resolving to "won't fix". 

The reason is that the old wst.javascript component is being removed this release, and replaced by the wst.jsdt component. 

So ... if any owners of these wst.javascript bugs see the same problem in the wst.jsdt code, then please open a new bug on that component. 

Apologies we can't check each ourselves, but there's just too many (and too few people) so we'll need community help. Just glancing, I know for sure many will no longer be bugs but some may still be legitimate requests even in the new JSDT code.