<!doctype html> forInherit </title> functionBasea ()//Base Class A { This. Member = "Basea Member"; This. Showselfa =function() {Window.alert ( This. Member); } } functionBaseb ()//Base Class B { This. Member = "BASEB Member"; This. SHOWSELFB =function() {Window.alert ( This. Member); } } functionExtendab ()//Inherit Class from A and B{Basea.call ( This);//Call for ABaseb.call ( This);//Call for B} window.onload=function() { varExtend =NewExtendab (); Extend.showselfa (); //Show AEXTEND.SHOWSELFB ();//Show B } </script> </body>
The results of the operation are as follows:
BASEB Member
BASEB Member
Test environment: Google Chrome
Results Analysis:
The expected result should be output BASEA member and BASEB member, but the actual output is BASEB member and BASEB member
In this way to achieve so-called multi-inheritance, the result: the same variable will be overwritten;
Of course, we can also make a slight modification to the above Basea code to verify the correctness of our debug analysis:
function Basea () // base Class Athis. Membera = "Basea Member"; // member changed to Membera to distinguish member in Baseb This function () { Window.alert (this. membera); // Show Membera }}
A misunderstanding of call and apply