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
*   
*/
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36e3c-2c07a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36e3c-2c07a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?