On Aug 23, 10:56 am, Stephan Beal <[EMAIL PROTECTED]> wrote:

> >   $("start").value += 1*$("rows").value;      // <- BUG!!
>
> Aha - .value is a STRING, but operator += IS defined for Strings, so
> it uses it and appends to the value.

and numbers too :-)

It depends on the language, some languages have specific CONCAT() like
functions.

>
> > To me,  that looks look like a JS type casting bug or inclusive
> > addition bug?
>
> It's not a bug, but a confusion about how the operators and type
> conversion apply. IMO += should not be overloaded for strings, to
> avoid exactly this type of problem. The fact that SOME of the built-in
> types have special operator overloads, but users of the language
> cannot overload any operators (except, indirectly, toString()), is a
> language design flaw, IMO.

Right, in JS theory it isn't a bug. :-)

Today, I work in about 7, maybe 10 different languages, including my
own languages for our product, keeping it all straight can be
daunting.   In our WCT processing, an intepreter with its own type-
less DOM, what I do is a conversion on both sides of dyadic
operators.  For example:

@SET v1 = 100@
@SET v2 = 200@

In our "DOM",  its it all store as "strings" so doing this:

@ADD V1 V2@

or in expanded form:

@SET V1 = V1 + V2@

both produced a numeric operation.

To force a string concatenation would be:

@SET V1 = ""+ V1 + V2@
@SET V1 = {V1}{V2}@

So part of the (my) problem was mentally thinking the similar ideas I
use across the board. :-)

Overall, in JS DOM,  one needs to mindful that storing a number can be
view as a string. Without thinking deeping of what you are saying as a
flaw,  jQuery, because of things like this and other things I came
across in the past 2+ weeks,  it has pretty much force me to take a
step back and study the DOM and the JS OOPS framework.

Basically, in short, there a String variables and there are String
objects as illustrated here:

   s1 = "Stephan";
   s2 = new String("Stephan");
   console.log(s1.valueOf());
   console.log(s2.valueOf());

As you can see in DOM, s1 and s2 are fundamentally different, but both
can be used as "strings".  s2 is a basically a class object, but as
you see above when you begin to access s1, JS will automagically type
case it as a String object allowing you to use String  methods as
well.

--
HLS

Reply via email to