N
N
neodekvat092015-08-13 04:55:45
JavaScript
neodekvat09, 2015-08-13 04:55:45

What is the best way to create a class in javascript?

Hello, I recently started to delve into OOP in js'e, everything seems to be clear, but still there are a couple of details that I cannot understand, one of them is what is the difference in new 'class' and object.create 'class ' what to use when creating child elements of class ?
Second, how is it better to create classes, in a prototypical or functional style? (the fact that methods are hung on prototypes, I know this) More precisely, as generally accepted, it is clear that prototypes are faster (I don’t remember for sure), but nevertheless: \
If you can, the answer is detailed, because I almost don’t found, and foreign articles are understood with difficulty (the complexity of the language).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-08-13
@neodekvat09

what is the difference in new 'class' and object.create 'class',

Object.create does not call the constructor, which is why it is so convenient to use it to expose other objects as a prototype.
js doesn't have classes. In any case, it is better to declare methods in the prototype.
https://babeljs.io/docs/learn-es2015/#classes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question