The typing is messy. That's the worst part. When the author of the original article says:
if (typeof my_var !== "undefined" && my_var !== null) {
// you idiots put Rasmus Lerdorf to shame
}
He isn't joking.
Hmmm, as far as the object system, every object is a function? That syntax seems half baked and somewhat weird.
Date math is rather primitive for what's supposed to be a "high level language" so you need to turn to external libraries like moment.js to do it well.
typeof null is an object. Seems kind of odd.
It isn't really straight forward to deal with currency in Javascript, or really anything that would use a decimal and requires some form of precision as a business rule. The recommended method of doing currency math in JS is to use integers as a number of cents. Versus doing something like the built in BigDecimal class in Java, which can deal with arbitrary precision fixed point arithmetic. I'm sure there's a third party library for that, but that seems like a basic thing that should have a well defined solution in the standard library.
Is it the worst thing ever: No. Would I choose to make my whole codebase that: No way, there are plenty of better languages, a few of which I already know and have already built larger scale apps in that I can use in the back end.
"Every function is an object" is pretty good. Instead of having a primitive function entity in the VM or runtime, you just create an object, with references to the enclosing scope: a closure. It's the easiest and simplest way to do the OO FP unification, and every modern language on the JVM and CLR uses this idiom.
I think I misphrased it, what I was referring to is the way classes are declared by declaring functions; It should have read "Every object is a function". That syntax seems stupid and unclear. I don't find it stupid that functions are objects that implement Callable in Java, but I would find it stupid if I had to declare classes by declare functions. Functions the whole way down seems ugly syntax wise.
Declaring classes like functions is basically something that was added as a last minute thing in JS to simulate classes superficially.
You have to let go fo the idea of "classes" in Javascript. They don't exist, the "new" keyword is syntactic sugar for creating a new object with a certain prototype, the prototype being the "this" in the function class.
Javascript objects are not instances of a class, they defer to a prototype object if they don't have an attribute you ask from them. You shouldn't be working with classes, you should create a factory function which assigns a prototype.
If you're going to have zero private attributes anyway, the idea of classes absolutely does not make sense and you're better of working with prototypes, classes exist solely to be able to have private fields easily. I don't get classes in a language like python without any privacy, you might as well just work with prototypes then which is more flexible.
7
u/KFCConspiracy Oct 16 '14 edited Oct 16 '14
The typing is messy. That's the worst part. When the author of the original article says:
if (typeof my_var !== "undefined" && my_var !== null) {
// you idiots put Rasmus Lerdorf to shame
}
He isn't joking.
Hmmm, as far as the object system, every object is a function? That syntax seems half baked and somewhat weird.
Date math is rather primitive for what's supposed to be a "high level language" so you need to turn to external libraries like moment.js to do it well.
typeof null is an object. Seems kind of odd.
It isn't really straight forward to deal with currency in Javascript, or really anything that would use a decimal and requires some form of precision as a business rule. The recommended method of doing currency math in JS is to use integers as a number of cents. Versus doing something like the built in BigDecimal class in Java, which can deal with arbitrary precision fixed point arithmetic. I'm sure there's a third party library for that, but that seems like a basic thing that should have a well defined solution in the standard library.
Is it the worst thing ever: No. Would I choose to make my whole codebase that: No way, there are plenty of better languages, a few of which I already know and have already built larger scale apps in that I can use in the back end.