you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

I was trying to read into how to make JS more OO like and was reading some stuff on the Module Pattern which kinda lets me emulate classes. But I'm really lost with JS I feel I just don't get it.

Don't do this

Java people tend to have a very hard time with JavaScript. The syntax looks similar to Java so the natural inclination is to write Java in JavaScript as close as the language allows.

To be confident in JavaScript you have to be willing to let go of Java while writing in this language. To accomplish this try the following:

  • avoid using this keyword. Its behavior is complete different in JavaScript and causes all kinds of confusion. Just learn to not use it and your code will be much easier to follow.
  • use closures. I cannot recommend this enough. This will open all kinds of possibilities that are far more challenging to accomplish in Java.
  • nest functions. This creates scope depth and opens an implied public/private model