What is the prototype chain??? The concept of C/c++/java class has been deep in my heart, and suddenly this is not suitable. What's the use?
And see the back ES6 grammar, unexpectedly also joined the class?????
What the hell? Isn't that a hit on your face?
Maybe there's something useful in the back, but I haven't found it yet.
A brief explanation of the prototype chain
78655038
Class inheritance is through the prototype chain, and class is an API that encapsulates the prototype chain.
Class allows us to write code like Java
Now first use class good, prototype chain to understand, after all, not in-depth study JS
class Student { / /constructor Constructor (name) { this. name = name; } // Method Hello () { alert (this. Name + '! ') ); }}
var xiaoming = new Student(‘小明‘);xiaoming.hello();
Inherited
class Primarystudent extends Student { constructor (name, grade) { // Remember to call the constructor of the parent class with Super! this . grade = grade; } Mygrade () { alert (this. grade); }
JavaScript learning-class/prototype chain/class