Vasya Pupkin2015-04-04 15:52:06
Vasya Pupkin, 2015-04-04 15:52:06

Advice in learning OOP JavaScript?

Recommend resources or books or screencasts to quickly get the hang of OOP JavaScript!
Thanks for watching and future replies!

Answer the question

In order to leave comments, you need to log in

5 answer(s)
Sergey, 2015-04-04
Protko @Fesor

How to quickly get into OOP in JS:
All objects. Objects have a constructor and a prototype. Creating a new object - copying the prototype to a new instance of the object and calling the constructor. The object instance will be used as the context for calling the constructor. The constructor is just a function that returns the call context by default, but you can return there and output any garbage.
It is important to understand that the prototype is copied. That is, if you created 10 instances of the same type, then changed the prototype, for example by adding a method), then the first 10 instances will not have these methods, but the new ones will.
Inheritance - just declare a type with your prototype. Due to some features, it is not so easy to inherit from some types without casters (for example, from an array).
To make things easier, ES2015 has a new syntax for declaring objects of their types.
The principles of OOP are the same as elsewhere, the only thing that is worth reading about modules for encapsulation is that in JS (as in some other languages) there are no access modifiers.

Ruslan Abdullaev, 2015-04-04

Stoyan Stefanov's book - "JavaScript. Templates"
Practically about the same, only with video - Alexander Samilyak about OOP in Javascript

dtestyk, 2015-04-04

you can start slowly es6 classes

Vyacheslav Golovanov, 2015-04-04


Alexey Yaroshevich, 2015-04-05

You can also use OOP in Ruby. www.theodinproject.com/ruby-programming/object-ori...
Take OOP in Ruby, cut off Classes and Meta-classes, add (instead of classes and metaclasses) your own implementation like https://github.com/dfilatov/inherit or any other - you get classes in JS.
ES6 classes, as far as I know, are just sugar, so don't get your hopes up - it won't go far from what it is now, it will just be possible to write more concisely.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question