On 2008-09-10, at 22:48EDT, Henry Minsky wrote:
In the debugger/LzMessage class, there is some code like this
function toArray () {
var array = [this.locationString(this.constructor.type)];
Which essentially gets the classname, via the static var "type", of
whatever subclass of LzMessage is
being operated on. I guess I can write this['constructor'].type, but I
wonder if there is a better way
to be doing this? This seems a little bit baroque.
This should be portable. If you have an object in JS the constructor
property of that object should be the class of the object. All this
code is trying to do is get at a static property of the class of the
object, but dynamically. The thing is, C++ apparently made everyone
believe you should not be able to access static properties in this way
-- because it did not want to support runtime introspection.
Apparently the 'portable' way to do this is to either: a) make the
property an instance property (waste space copying it into each
instance), or b) write a getter method to retrieve the property (waste
time making a method call). Bleah.
So, yes, I guess instead of:
class LzError extends LzSourceMessage {
static var type = 'ERROR';
static var color = '#ff0000';
...
You'll have to write:
class LzError extends LzSourceMessage {
function override messageType () { return 'ERROR'; }
function override messageColor () { return '#ff000'; }
...
Oh well.
Maybe we should be overriding a "classname()" method on each of the
subclasses of LzMessage? Seems
like that would be more readable. Just trying to keep things easy to
understand/maintain....