Puzzled wrote:
> Stefan Weiss wrote:
>> Hope this gets you on the right track.
>
> It did, and *many* thanks for that.
>
> At first I resisted accepting what you were obliquely telling me
> because I found it too hideous to contemplate. But after downing
> a pint of whisky (no, not really) I relaxed enough to think about
> it. It's still eye-wateringly hideous, but I've always been able
> to accept reality when I've no other choice.
I still say that this is the only good time to accept reality! Don't
do so if you have any choice.
> To me, the key concepts here are
>
> a) js is at best pseudo-oo because it doesn't maintain under all
> circumstances the defining oo relationship: that of the object
> instance to its properties.
Javascript can certainly be used as an OO language. The fact that it
uses prototypal rather than classical inheritance is the main
difference between it and more mainstream OO languages.
But it is not an OO-only language in the way that, say, Java or C# are
OO languages. I often use it more as a functional language.
I think what you're reacting to is the fact that functions are first-
class objects. Although they can be used as object methods, they are
not simply object methods. I'm afraid you won't get much support here
that this is horrible. I imagine many other regulars would agree with
me that this is one of the best features of the language.
> b) a within-element event "binding" remains, at least in effect,
> nothing but a string until source-interpreted ...
When you say "within-element", you are confusing two different
languages. Javascript can be embedded within HTML, and that is in
essence what you're doing with code like this. There are various ways
to bind event handlers to document nodes. When you do it in markup
like this, you have to live with the restriction that markup is just
text to be interpreted. There are many alternatives. One is
demonstrated at
<
http://jsfiddle.net/CrossEye/wxQ2K/>
(I didn't understand your requirements well enough to try to use your
terminology, but this should show the ideas.)
>(eeeuw, shades of lisp and apl)
Yahoo, shades of SCHEME and LISP! :-)
> ... during the lookup process that determines who
> should service the current event. It's that choice --to delay
> the binding until the object relationship has been lost-- that
> makes js a pseudo-oo language.
Again, this seems to be a confusion between the JS and the HTML. You
are creating some HTML representing elements to be added to the
document. Your Javascript has been left behind at this point.
> So, the solution (in my case at least) is to maintain within each
> instance the name of the instance and substitute it as the
> self-ref for within-element bindings, e.g.
>
> var foo = constr('foo'...
> function constr( selfid,...)
> { this.InstName = selfid ; this.click_esr = cesr ; }
> function cesr( j ) {...}
>
> <a .... onclick="'+this.InstName+'.click_esr('+i+...');">'+...
That's one way, but there are so many alternatives. If you're
generating the elements within code (rather than generating markup
that the HTML engine must interpret to make elements) then there are
much more elegant techniques.
> Thanks to everyone who tried to explain to me the full
> horribleness of what's going on.
You may find that Javascript is not to your liking, but you're not
likely to get too much sympathy in comp.lang.javascript for the notion
that the language is horrible. ;-)
-- Scott