Andreas said:
Am 17.10.2007 15:13 The Natural Philosopher wrote
You mean like:
document.writeln(10+5);
?
Gives 15 in both IE6 and Firefox here.
And:
document.writeln("10" + "5");
gives "105".
While typeless languages ain't the holy grail, typed ones ain't either.
Maybe you should start out by RTFM ;-)
I did RTFM, and discovered that it is not really possible to tell what a
variable is.
Here i what I ended up with.
function bom_set()
{
var cost, index,margin, sale_price;
cost=Math.round(document.getElementsByName('kitcost')[0].value);
document.getElementsByName('unit_price')[0].value=cost/100;
index=document.forms[0].margin.selectedIndex;
margin=document.forms[0].margin[index].value;
document.getElementsByName('sale_price')[0].value=Math.round(
(Number(margin)+1000)*cost/1000)/100;
document.getElementsByName('bargain')[0].value=Math.round(
(Number(margin)+1000)*cost *0.9/1000)/100;
}
Note that multiplication and division of what I assume is an implicit
string, picked up from a form variable, worked as intended. Use of the
addition operator did not.
A simple choice of a dot operator rather than a plus for string
concatenation, as PHP does, would have made the whole language more
sensible.
Its sloppy ambiguity built into the language IMHO. If you throw away
typing, you ought to have a responsibility for making a given construct
unambiguous.
Use of overloaded operators in strongly typed language is fair enough:
the operator does what its intended according to the type of the operands.
In a weakly typed language its pretty much an unmitigated disaster as
far as I am concerned.
Still life is life, and one learns to work around other peoples shit
with the appropriate shovel.
Now come and tell me that Number(10) will return an error, because 10 is
not a string ...;-)