JavaScript or rather JS1.0 is mostly a baby Perl with Java syntax. The prototype object system from Self being the main difference (objects are kind of blessed hashes which inherit from other objects not classes)
The claimed functional influence from Scheme is already present in Perl5. ( sub returns a function reference, making functions a first class object which can be treated like variables)
Block scoping was later introduced into JS with let . ( var is a mess )
The operators you list derive from C, a common predecessor for Perl and Java.
Actually "typecasting" in JS is a major problem, JS has no "scalars".
To better explain, there are two major ways to do dynamic typing.
A) a type is determined when initializing.
Like in Python where 3/2 is 1.
Why? Because 3 and 2 are integers. (Python introduced something like // later to address the confusion)
B) a type is determined by the operator.
Like in Perl where 3/2 is 1.5 and 3 . 2 is 32
JavaScript is a mongrel of both systems,
and the rules how + behaves confuse(d) the shit out of people.
You can remember that 1 + "1" is "11", but what will happen if you don't have full control about the types in the variables of a + b ?
JS programmers must resort to tricks like
'a+b+0' or 'a+b+""'
(IIRC, this depends on precedence and I have to look it up to be sure UPDATE guess what, I got it wrong, have to correct this later.
What's sure is that a+=0 becomes a number and a+="" a string )
Perl fixed this with a lot of operators, but people complain that the code looks unreadable, because of all the symbols.
But Brendan had 10 days to design the language which had to look like Java...
They fixed a lot of stuff in the meantime and introduced some nice python features.
But it's still annoying not to have pure hashes in JS ...
|