Does JavaScript also have the concept of interface and inheritance? Then what keywords are used to implement the interface or inheritance

JavaScript

Node

Dec.29,2021
The concept of

exists all the time. Es6 inherits



document.createElement



js is based on prototype inheritance, and there are no good keywords to implement interface and inheritance, so it needs to be simulated. You can find information about js design patterns to get the simulation.
es6 introduces classes and inheritance, but it is not perfect compared to traditional object-oriented languages. If you must use complete mechanisms such as inheritance and interfaces, you can choose to use typescript.


Yes, both es6 and typescript are implemented. It's not realistic to implement it by yourself. Take a look at es6's
es6's class inheritance


all the time. Encapsulate inheritance and polymorphism.


conceptually, there is no interface in syntax. Although there are a lot of inheritance in es5, except for prototype chain inheritance, everything else is copied. Es6 has an extends, equivalent to inheritance in java. For oo, let's use ts. Es6 is not enough.


you can use a factory function to reflect the form of the interface

var instance = function(){
    var var0 = 0;
    var interface = {
        var1 : var0
    };
    return interface;
}

inheritance is also called replication, reuse code

var father = {
    firstName: 'liu',
    lastName: 'oneDog',
    age: 20
};
var son = {
    lastName:'twoDog',
    age: 2
};
/**
*  
*/
Object.assgin(son,father);
/**
*   
*    prototype
*   
*/
Menu