JavaScript OOP in NodeJS: how?

前端 未结 6 1942
野的像风
野的像风 2021-01-29 18:31

I am used to the classical OOP as in Java.

What are the best practices to do OOP in JavaScript using NodeJS?

Each Class is a file with module.export

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-29 18:52

    This is the best video about Object-Oriented JavaScript on the internet:

    The Definitive Guide to Object-Oriented JavaScript

    Watch from beginning to end!!

    Basically, Javascript is a Prototype-based language which is quite different than the classes in Java, C++, C#, and other popular friends. The video explains the core concepts far better than any answer here.

    With ES6 (released 2015) we got a "class" keyword which allows us to use Javascript "classes" like we would with Java, C++, C#, Swift, etc.

    Screenshot from the video showing how to write and instantiate a Javascript class/subclass:

提交回复
热议问题