loading...

re: What was the most difficult thing to learn about JavaScript for you? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: For me, it is classes and OOP. I know the syntax, I know how it works. but I don't know where and when to use it. I have been coding in Express.js...
 

Classes are definitely one of those things in JavaScript that were added for OO Devs (c#, Java, etc). If you don't need them and are fine with functional programming, then go for it.

 

I'd like to point out that JavaScript has always been an object oriented programming language, at least as far as I've known about it.

Prototypal inheritance is OOP. It's just that we tend to think that the only type of OOP is class based inheritance.

JS didn't change, it still uses protypal inheritance and as you mentioned, they added classes mainly as syntactic sugar.

en.wikipedia.org/wiki/Object-orien...

You have objects, they can encapsulate state, they receive messages from the outside using their public interface at runtime, that's more or less all there is for a basic OO language.

If you look closely at Python source code you'll notice how one in theory could implement object orientation directly in C, this is the constructor of a Python object:

PyObject *
_PyObject_New(PyTypeObject *tp)
{
    PyObject *op;
    op = (PyObject *) PyObject_MALLOC(_PyObject_SIZE(tp));
    if (op == NULL)
        return PyErr_NoMemory();
    return PyObject_INIT(op, tp);
}

from github.com/python/cpython/blob/014...

True, I got ahead of myself. Prototypal Inheritance is different than class inheritance, but both are OOO. The use of classes in Javascript with their introduction in ES6, has helped many developers get over this initial difference. But as you said, it really is just syntactical sugar over the same ole' prototypal inheritance chain.

code of conduct - report abuse