OOP with JavaScript

I'm coding with JavaScript on Node.js for the moment, and I was asking myself if there is a convenient way for using classes with private and public properties (and methods). I'm coming from PHP so are there any similar structures?

I've been doing it for the moment with modules, I export the public methods and vars en keep the rest private, is that the right way? And are there any good guides on going OOP with JavaScript?

In Javascript the concept of "private" doesn't really exist, although it is possible once you get the hang of the language a bit more.

Here's a good introduction to OOP in Javascript: https://developer.mozilla.org/en-US/docs/JavaScript/Introduction_to_Object-Oriented_JavaScript

Javascript can emulate (or rather replace) some/most class behavior using prototyping, but to someone used to classes, the syntax can be a bit confusing. If you're going to work with Javascript professionally, learning prototyping is more or less a must though.

ECMAScript 6 which will probably eventually make its way into Javascript is rumored to add support for classes. It is not available yet though :-/

Typescript is a rather highly debated Javascript extension by Microsoft that adds some class support and strong typing for Javascript. It compiles down to standard Javascript, or can be added as a module to node.js.

You can achieve a "class structure", although what you would really be doing is making an object literal behave like a class.

I can understand why it might be confusing, especially when you read for example Backbone JS's documentation - they define their objects as classes - when really there are no classes! Only object definitions.

Using a framework such as Backbone makes things a lot easier to understand, because you are working with a class like structure. Might be a good place for you to start.