Is there any problem in writing js inheritance compared to js parasitic combinatorial inheritance?

    function Sup(){
        this.name = "adc";
        this.arr = [1,2,3];
    }

    Sup.prototype.say = function(){
        console.log(this.arr)
    }

    function Sub(){
        Sup.call(this)
    }

    Sub.prototype = Sup.prototype

    var c1 = new Sub()
    var c2 = new Sub()
Feb.28,2021

reference question
directly assign Sub.prototype and Sup.prototype to the same memory address
all will interact with each other Sup the prototype method defined in Sub , there will also be
generally: Sub.prototype = Object.create (Sup.prototype)


upstairs the positive solution
problem is very big, and you want to give Sub. It is equivalent to adding a method to the child but modifying the parent's prototype. If you have another Sub1 , then Sub1 will also have the methods you add, which is certainly not what we expected.

Menu