0

I have to admit that I don't fully understand NodeJS. But I am thinking about using it. However what I don't understand why did the founder of NodeJS go with JavaScript? Why not with a language where for example OOP is more simple?

Ok I found some answer.

  1. JavaScript is perfect for event loops with first class function objects and closures. People already know how to use it this way having used it in the browser to respond to user initiated events.

  2. A lot of people already know JavaScript, even people who do not claim to be programmers. It is arguably the most popular programming language.

  3. Using JavaScript on a web server as well as the browser reduces the impedance mismatch between the two programming environments which can communicate data structures via JSON that work the same on both sides of the equation. Duplicate form validation code can be shared between server and client, etc.

Source: What is Node.js?

But I still don't get why is it so difficult to use basic things like classes in NodeJS. Ok maybe not difficult but all the solution look like some kind of a hack job.

Edit: Why the down vote?

Community
  • 1
  • 1
yoshi
  • 1,287
  • 3
  • 15
  • 28

1 Answers1

2

This question will, undoubtedly, get closed, since it's looking for opinions, but there are some objective questions in your post, so I'll answer those.

Classes are only "basic things" in OO languages that are class based, like in Java. JavaScript is what's known as a prototypal OO language. This means that it is prototype based.

A prototype is an object that is used for generating other object. In fact, there's actually nothing special about an object that is being used as a prototype. As such, any object can be used as the prototype for a new object.

Prototypal OO can certainly be tricky if you're not used to it. However, as implemented in JS, it brings a lot of flexibility. However, with great flexibility comes great opportunities for writing bad code.

Dancrumb
  • 26,597
  • 10
  • 74
  • 130