Home  >  Article  >  Web Front-end  >  What to learn before learning react.js

What to learn before learning react.js

(*-*)浩
(*-*)浩Original
2019-05-18 14:25:063461browse

You must learn the basics of JavaScript before learning reactjs, because React is a JavaScript library used to build user interfaces, most of which are JavaScript ES6 and its features and syntax, including ternary operators and simplified syntax. , this object, JavaScript built-in functions, etc.

What to learn before learning react.js

#In the process of introducing React to others, I came to the conclusion that React is all about JavaScript. Also, there is a lot of material about JavaScript rather than React.

Most of this is JavaScript ES6 and its features and syntax, but also includes the ternary operator, simplified syntax, the this object, JavaScript built-in functions (map, reduce, filter) or more general concepts such as Composition, reusability, immutability, or higher-order functions. You may not need to master these basics before getting started with React, but you will definitely need to use them during learning or practice.

React and JavaScript classes

For React class components, prior knowledge of JavaScript classes is required. The concept of JavaScript classes is relatively new. Previously, only JavaScript's prototype chain could be used to implement inheritance. JavaScript classes are based on prototypal inheritance, making the inheritance system simpler.

One way to define React components is to use JavaScript classes.

class Developer {
 constructor(firstname, lastname) {
   this.firstname = firstname;
   this.lastname = lastname;
 }
 getName() {
   return this.firstname + ' ' + this.lastname;
 }
}
var me = new Developer('Robin', 'Wieruch');
console.log(me.getName());

A class describes an entity and is used to create instances of the entity. When you create an instance of a class using the new statement, the class's constructor is called. Properties of a class are usually located in the constructor. In addition, class methods (such as getName()) are used to read (or write) the instance's data. Instances of a class are represented within the class using the this object, but externally, they are only assigned to JavaScript variables.

In object-oriented programming, classes are usually used to implement inheritance. In JavaScript too, the extends statement can be used to make one class inherit from another. A subclass inherits all the functions of a parent class through the extends statement, and can also add its own functions.

class Developer {
 constructor(firstname, lastname) {
   this.firstname = firstname;
   this.lastname = lastname;
 }
 getName() {
   return this.firstname + ' ' + this.lastname;
 }
}
class ReactDeveloper extends Developer {
 getJob() {
   return 'React Developer';
 }
}
var me = new ReactDeveloper('Robin', 'Wieruch');
console.log(me.getName());
console.log(me.getJob());

The above is the detailed content of What to learn before learning react.js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn