So in this post we will cover the following language-level issues:
- Inheritance differences from Java
The good things to know
Write once – run mostly anywhere!
Functional programming: Functions are first class citizens, Recursion is not so
Inheritance: just like in the real world
Imagine an object A being like a map, we touched this matter a bit above but here’s a different angle, and then another map-like object B is said to inherit everything from A.
What it means is that B has access to what A consists of, its methods, fields and so forth.
— Rene Saarsoo, XRebel Frontend Engineer at ZeroTurnaround
I’m not really sure what a Java developer should take from this, but beware of this difference in the inheritance organisation and pay extra attention to parent objects not to accidentally change the behavior of the whole program.
Avoid these at all costs
Alternatively, enable the strict mode. Just write “use strict” at the top of the script file and your unintentional global variable declarations will become errors.
Tracking a variable that was a String once, but now is a floating point number or a function gives little pleasure, trust me!
Tips for getting stuff done
As I mentioned in the beginning there is more to programming than knowing the syntax and quirks of the language in use. Project rarely fail because the language is lacking. More often failures are related to the general project architecture inefficiencies. Here are some tools that can help you with delivering the project.
Static code analysis
Most projects are different and their complexity and requirements contribute a huge amount of details to how you want to approach the codebase. However, there is one goal that is consistent between all of them: code quality.
Yeah, I get it, the most important thing for any developer is to ship things. But don’t compromise on the quality, don’t get into a state when you are embarrassed for the code you pushed and reluctant to share it with the teammates.
Repl stands for read-eval-print loop and is a great tool for more dynamic languages. If you’ve looked at Scala or Groovy you definitely recognise the concept.
Another tool that can be of convenience is jjs , which comes bundled with JDK 1.8.
In Jasmine, you describe your test-suites with describe and it blocks that access the code you want to test. After the code under test does its job, you expect things.
There are tons of plugins available and you’ll find the collaboration on a project much easier with the build system in place.
Do you know a secret or best practice that can lead a JS developer to a happier place? No doubt it should be shared! Leave a comment below or find and chat with me on Twitter: @shelajev. I’d love to hear your thoughts!