With the help of the tips suggested in this guide, you will write code that is understandable to any development team. These recommendations are not necessary to follow, these are the basic rules that will help you learn how to write more consistent and understandable code. To effectively apply the proposed rules in practice, start right now, share them with your classmates, and use them. However, do not get hung up on these rules, as it can be counterproductive. Try to find your own solution while dealing with your assignment on ES5 to ES6.
Read through the sample right now!
Classes and objects
In ES6 there is a new syntactic sugar. You can do the same with a smaller code and using the class and construсtor keywords. Also note how the methods are defined clearly: construtor.prototype.speak = function () vs speak (): ES6
Always use the syntax class and do not modify the prototype directly. The code will be laconic, and it will be easier to understand. Avoid creating an empty constructor. The classes have a default constructor if you do not specify your own.
Let’s continue the previous example with the Animal class. Let’s say we need a new Lion class. In ES5 you have to work a little with the prototype inheritance.
In line 3, we directly call the Animal constructor with parameters. Lines 7-8 assign a Lion prototype of the class Animal. In line 11, we call the speak method from the parent class Animal.
In ES6 there are new keywords: extends and super.