Js prototype chain inheritance

        function Foo1(){
           this.name1 = "1";
        }
        function Foo2(){
           this.name2 = "2";
        }
        Foo2.prototype = new Foo1();
        function Foo3(){
           this.name = "3";
        }
        Foo3.prototype = new Foo2();
        var foo3 = new Foo3();
        console.dir(foo3);

help me analyze why the place where the arrow points is printed is not Foo2 but Foo1,. What is the principle?

Mar.06,2021

because you copy the instance of Foo1 to the prototype of Foo2, and Foo2.prototype.constructor points to Foo1, if you add a line after Foo2.prototype=new Foo1 to modify constructor to Foo2. You should be able to get the results you want.


The process of

new is like this, you can see it at a glance.

var obj={};
obj._proto_=Father.propotype;
Father.call(obj);
return obj;

Foo3 points the prototype to Foo2, through the prototype attribute, but in the end the prototype of Foo2 is also Foo1

.
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-1b3c40e-2c2ef.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-1b3c40e-2c2ef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?