473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

OO JavaScript? Who's using it?

Just by way of introduction, I'm currently the principal developer and
maintainer of the a JavaScript editor plug-in for Eclipse.

[https://sourceforge.net/projects/jseditor/ The plug-in as it stands
supports syntax highlighting and outlining of functions, classes and
their methods.]

When I took over the project in June it was for the purpose of adding
outlining facilities for JavaScript written in an OO style with classes
and so on. I have since discovered, to both my delight and horror, that
there are a variety of ways of accomplishing OO in JavaScript.

I was wondering if any of those people currently involved in large
JavaScript projects might be willing to provide me with some input on:

- the style they use
- what kind of editor support they would find useful

I look forward to your input. (And if you don't feel the newsgroup is
the right place for this, there are discussion forums on the website
maintainted by sourceforge...)

Cheers! [And season's greetings!]

--
Alex
Jul 20 '05 #1
6 1966
"Alex Fitzpatrick" <al*********************@videotron.nospam.ca> wrote
in message news:6E********************@wagner.videotron.net.. .
<snip>
When I took over the project in June it was for the purpose
of adding outlining facilities for JavaScript written in an
OO style with classes and so on.
It has often been questioned in this group whether JavaScript has any
structures that can reasonably be labelled a "class", or whether any
terminology from class-based languages should be applied to JavaScript.

Personally I don't mind using "class" to describe a particular sub-set
of JavaScript object definitions, but only as a convenient label and
only if the corresponding code is employed in a way that does not render
the term inapplicable (Given the runtime mutability of both object
instances and constructor prototypes).
I have since discovered, to both my delight and horror,
that there are a variety of ways of accomplishing OO in
JavaScript.
And there is the problem, JavaScript is wonderfully flexible both in
terms of the structures that can be defined and the way in which they
can be employed.

There is also the question of what separates an object from a function
(as functions are function objects) and so: when would a code structure
that resulted in instances of function objects with public and possibly
(closure emulated) private members (and possibly also public static and
(closure emulated) private static members) qualify as equivalent to a
"class"? A question that might be best illustrated with code:-

var TimedQue = (function(){
var base, timer;
var interval = 50;
var newFncs = null;
function addFnc(next, f){
function t(){
next = next&&next();
if(f()){
return t;
}else{
f = null;
return next;
}
};
t.addItem = function(d){
if(next){
next.addItem(d);
}else{
next = d;
}
return this;
};
t.finalize = function(){
return ((next)&&(next = next.finalize())||(f = null));
};
return t;
};
function tmQue(fc){
if(newFncs){
newFncs = newFncs.addItem(addFnc(null, fc));
}else{
newFncs = addFnc(null, fc);
}
if(!timer){
timer = setTimeout(tmQue.act, interval);
}
};
tmQue.act = function(){
var fn = newFncs, strt = new Date().getTime();
if(fn){
newFncs = null;
if(base){
base.addItem(fn);
}else{
base = fn;
}
}
base = base&&base();
if(base||newFncs){
var t = interval - (new Date().getTime() - strt);
timer = setTimeout(tmQue.act, ((t > 0)?t:1));
}else{
timer = null;
};
};
tmQue.act.toString = function(){
return 'TimedQue.act()';
};
tmQue.finalize = function(){
timer = timer&&clearTimeout(timer);
base = base&&base.finalize();
newFncs = [];
};
return tmQue;
})();

TimedQue is a DHTML animation timer. The object assigned to the named
global variable is a function and it is employed by calling it with a
function reference as an argument. It adds the function to an internal
queue and then arranges that the function be repeatedly executed at
intervals so long as it returns true, dropping the function from the
queue as soon as its execution returns false (or type-converted
equivalent).

From one point of view TimedQue is just a function but it has two public
methods and might be said to have 5 private members. But a better
candidate for consideration is the function - t - returned by calls to -
addFnc - as it two has public methods and multiple instances of the
function object, defined with the code within the - addFnc - function,
are created. So does the code within the - addFnc - function qualify as
an inner "class" definition?

From the point of view of wanting to apply class-based terminology to
JavaScript TimedQue is an (the) instance of a singleton class with 2
public methods and 5 private members including a private factory method
that returns instances of the - t - inner class. It is going to be a
pain to try to pull that interpretation out from the source code, and
there is not one single instance of the JavaScript - Object - "class"
created or employed anywhere in the above code.
I was wondering if any of those people currently involved
in large JavaScript projects might be willing to provide
me with some input on:
Given the date, is anyone currently involved in anything? ;)
- the style they use
That is not an easy question to answer. The flexibility that JavaScript
offers means that tying yourself down to a ridged concept of "class" or
any one pattern of object definition/instantiation might be working
against the strengths of the language. I tend to be flexible and
consider what the code is going to do as the various styles all involve
some trade-off or another.
- what kind of editor support they would find useful


I am not sure, I tend to use textPad though it only recognises 6 keyword
classes when syntax highlighting and I would like probably 10 or so.

Richard.
Jul 20 '05 #2
Richard Cornford wrote:
"Alex Fitzpatrick" <al*********************@videotron.nospam.ca> wrote
in message news:6E********************@wagner.videotron.net.. .
<snip>
When I took over the project in June it was for the purpose
of adding outlining facilities for JavaScript written in an
OO style with classes and so on.

It has often been questioned in this group whether JavaScript has any
structures that can reasonably be labelled a "class", or whether any
terminology from class-based languages should be applied to JavaScript.

Personally I don't mind using "class" to describe a particular sub-set
of JavaScript object definitions, but only as a convenient label and
only if the corresponding code is employed in a way that does not render
the term inapplicable (Given the runtime mutability of both object
instances and constructor prototypes).


A very good point, but this would be very a confusing distinction for
many people, so I don't try to go there outside of an academic setting.

Perhaps what we need is a strong etymology of class-like constructs that
are possible in a prototype oriented language. Clearly class-like is
just one.
I have since discovered, to both my delight and horror,
that there are a variety of ways of accomplishing OO in
JavaScript.

And there is the problem, JavaScript is wonderfully flexible both in
terms of the structures that can be defined and the way in which they
can be employed.

There is also the question of what separates an object from a function
(as functions are function objects) and so: when would a code structure
that resulted in instances of function objects with public and possibly
(closure emulated) private members (and possibly also public static and
(closure emulated) private static members) qualify as equivalent to a
"class"? A question that might be best illustrated with code:-


-Example snipped for brevity- - nice example though-

This kind of syntax should be supportable, right down to the "inner"
class. JSEditor does not currently handle private members or inner
classes, but I'm hoping to add this soon.
From one point of view TimedQue is just a function but it has two public
methods and might be said to have 5 private members. But a better
candidate for consideration is the function - t - returned by calls to -
addFnc - as it two has public methods and multiple instances of the
function object, defined with the code within the - addFnc - function,
are created. So does the code within the - addFnc - function qualify as
an inner "class" definition?
Yup, and TimedQue is just implementing a Factory pattern! :-)
From the point of view of wanting to apply class-based terminology to
JavaScript TimedQue is an (the) instance of a singleton class with 2
public methods and 5 private members including a private factory method
that returns instances of the - t - inner class. It is going to be a
pain to try to pull that interpretation out from the source code, and
there is not one single instance of the JavaScript - Object - "class"
created or employed anywhere in the above code.


No problem at all. I just wish I could prove that today. Perhaps you've
just given me something to target for January.
I was wondering if any of those people currently involved
in large JavaScript projects might be willing to provide
me with some input on:


Given the date, is anyone currently involved in anything? ;)


Everyone's a comedian on UseNet. :-)
- the style they use

That is not an easy question to answer. The flexibility that JavaScript
offers means that tying yourself down to a ridged concept of "class" or
any one pattern of object definition/instantiation might be working
against the strengths of the language. I tend to be flexible and
consider what the code is going to do as the various styles all involve
some trade-off or another.


How about some more examples, that previous one was good.
- what kind of editor support they would find useful


I am not sure, I tend to use textPad though it only recognises 6 keyword
classes when syntax highlighting and I would like probably 10 or so.


What keyword classes would those be?

How about class browsing like Smalltalk or the Java Browsing Perspective
in Eclipse?

How many class-like behaviors do you maintain?

[I got started in this project because my employer was looking at a
project that would lead to hundreds of JavaScript classes. Doing this
with several developers meant that TextPad was not sufficient and
Eclipse offered no license fees and Perforce integration. (And some
future hope of UML integration.)]

Thanks for your input, it's nice to hear from others in the community.
[It was also nice to see some elegant code that I understood even though
I would have expressed it differently.]

--
Alex
Jul 20 '05 #3
Alex Fitzpatrick wrote:
Richard Cornford wrote:
Personally I don't mind using "class" to describe a particular sub-set
of JavaScript object definitions, but only as a convenient label and
only if the corresponding code is employed in a way that does not render
the term inapplicable (Given the runtime mutability of both object
instances and constructor prototypes).
A very good point, but this would be very a confusing distinction for
many people,


So these people should learn the language that they are using in *any* way.
so I don't try to go there outside of an academic setting.

Perhaps what we need is a strong etymology of class-like constructs that
are possible in a prototype oriented language. Clearly class-like is
just one.


Class-like is simply worng. Prototypes are fundamentally different
from classes since every object can be the prototype of another, and
OTOH two objects can have different properties even if they have
been created with the same constructor function. In prototype-based
languages like JavaScript 1.x, there is no strict class-binding that
imposes something else.
PointedEars, currently using JSEditor 0.3.3
Jul 20 '05 #4
Alex Fitzpatrick wrote:
Just by way of introduction, I'm currently the principal developer and
maintainer of the a JavaScript editor plug-in for Eclipse.
Thank you, and keep up the good work.
[https://sourceforge.net/projects/jseditor/ The plug-in as it stands
supports syntax highlighting and outlining of functions, classes and
their methods.]

When I took over the project in June it was for the purpose of adding
outlining facilities for JavaScript written in an OO style with classes
and so on. I have since discovered, to both my delight and horror, that
there are a variety of ways of accomplishing OO in JavaScript.
And there are no classes in JavaScript 1.x.
I was wondering if any of those people currently involved in large
JavaScript projects might be willing to provide me with some input on:

- the style they use
You need to be more specific. For now, read my postings here and in
de.comp.lang.javascript (if you can manage it), have a look at
http://pointedears.de.vu/scripts/ and feed the scripts to the plugin.
- what kind of editor support they would find useful


More and more reliable syntax highlighting, see my library
documentations (.htm) for examples (they use the style.css
file). With eclipse 3.0M4 and JSEditor 0.3.3, which I
understand for the latter is the latest release, the plugin
tends to forget where syntax highlighting should be applied.
Example: I often type

var foobar

where `var' is sometimes not hightlighted. When I then remove
the `v' and include it again, the keyword is finally highlighted.

Only constructor functions where the `this' special operator is
used are considered constructor functions by the plugin (then
falsely displayed as (C)lass in the Outline view). This is
obviously caused by the misguided attempt to impose class-based
terminology over a prototype-based language (see my other posting).
A function should be at least considered a constructor function if
it contains the `this' operator or is called with the `new' operator.
Example: math.js, where Exception is considered a "class" while
specialized exception functions are not, even if they are called
with the `new' operator in common functions.

When properties are unconditionally added to the prototype property
of an object, they should also appear as properties in the Outline
view.

A built-in JavaScript beautifier (and uglyfier ;-)) is needed.
Unlike the Java Editor's formatter, which was IIRC usable for
formatting JavaScript until eclipse 3.0M3, it needs to pay
attention to dynamic HTML, so that `<' within a string is not
considered an operator aso.

It would be nice if one could create a coder's documentation from
JavaScript source using special comments, like JavaDoc and PHPdoc
already do. Thus I have recently developed JavaScriptDoc[tm]:

http://pointedears.de.vu/scripts/JSDoc/

A working implementation of it in JavaScript (using quite cruel RegExp
parsing) is underway, but as the eclipse platform may already provide a
parser suitable for JavaScriptDoc, I would be glad if it could be part
of the JSEditor plugin once possible syntax inconsistencies have been
resolved.

These are my suggestions so far.

(Unlike your From header, headers of my postings conform to Internet
standards, and) I also welcome replies via electronic mail.
PointedEars
Jul 20 '05 #5
Thomas 'Ingrid' Lahn wrote:
PointedEars, currently using JSEditor 0.3.3


D'oh! It's 0.0.3, of course.

And I see that 0.0.4 is now available. D'oh again? ;-)
PointedEars, upgrading
Jul 20 '05 #6
Thomas 'Ingrid' Lahn wrote another monologue ;-)
Thomas 'Ingrid' Lahn wrote:
PointedEars, currently using JSEditor 0.3.3


D'oh! It's 0.0.3, of course.

And I see that 0.0.4 is now available. D'oh again? ;-)


JFYI: JSEditor 0.0.4 does not work with eclipse 3.0M4 (the preferences
page is missing and the editor cannot be associated.) So I stick to
0.0.3 until I have the opportunity to download the latest platform
milestone (> 70M) via DSL.
PointedEars
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.