Christopher Lenz
2004-02-27 19:09:16 UTC
Howdy folks,
I've been investigating the JavaScript plugin today. I hope that the
outline page and classes view are fixed now, at least they're working
for me.
Anyway, I've been thinking about the structured presentation of
JavaScript in views such as the outline page, and I'm not sure the
current approach is really appropriate. JavaScript is being treated by
us as if it were a more declarative/static, less dynamic language than
it is. For example, for the outline we turn the following JavaScript
snippet:
function Point(x, y) {
this.x = x;
this.y = y;
}
new Point();
Point.prototype.toString = function() {
return "[Point " + x + ", " + y + "]";
}
into a "class" with the "instance variables" x and y, and the "class
method" toString.
This doesn't seem quite right to me: Point is a constructor. The
constructor adds properties to the object being constructed. (BTW, what
makes a constructor a constructor? just adding properties to 'this'?).
Point objects, like all objects in JavaScript, have a prototype, which
is the closest thing JavaScript has to a class. We add a function to
that prototype. We could also have done that in the constructor.
But we could also do:
if (debug) {
Point.prototype.toString = function() {
return "[Point " + x + ", " + y + "]";
}
}
Thus the method would only get "declared" if the debug variable
evaluated to true. And that's only the simplest variant of dynamic
stuff you can do in JavaScript.
I have no idea how such dynamism could be correctly outlined. As I
said, our current approach seems a bit cheesy to me, because we are
basically trying to fit JavaScript into the constraints of a static
language.
Does anyone have any insight to share here? Do you know tools that
provide sensible outlines for JavaScript?
Cheers,
Chris
--
Christopher Lenz
/=/ cmlenz at gmx.de
I've been investigating the JavaScript plugin today. I hope that the
outline page and classes view are fixed now, at least they're working
for me.
Anyway, I've been thinking about the structured presentation of
JavaScript in views such as the outline page, and I'm not sure the
current approach is really appropriate. JavaScript is being treated by
us as if it were a more declarative/static, less dynamic language than
it is. For example, for the outline we turn the following JavaScript
snippet:
function Point(x, y) {
this.x = x;
this.y = y;
}
new Point();
Point.prototype.toString = function() {
return "[Point " + x + ", " + y + "]";
}
into a "class" with the "instance variables" x and y, and the "class
method" toString.
This doesn't seem quite right to me: Point is a constructor. The
constructor adds properties to the object being constructed. (BTW, what
makes a constructor a constructor? just adding properties to 'this'?).
Point objects, like all objects in JavaScript, have a prototype, which
is the closest thing JavaScript has to a class. We add a function to
that prototype. We could also have done that in the constructor.
But we could also do:
if (debug) {
Point.prototype.toString = function() {
return "[Point " + x + ", " + y + "]";
}
}
Thus the method would only get "declared" if the debug variable
evaluated to true. And that's only the simplest variant of dynamic
stuff you can do in JavaScript.
I have no idea how such dynamism could be correctly outlined. As I
said, our current approach seems a bit cheesy to me, because we are
basically trying to fit JavaScript into the constraints of a static
language.
Does anyone have any insight to share here? Do you know tools that
provide sensible outlines for JavaScript?
Cheers,
Chris
--
Christopher Lenz
/=/ cmlenz at gmx.de