ECMAScript only supports inheritance, does not support interface implementations, and implements inheritance in a way that relies on the prototype chain to complete
The structure of the relationship between the prototype + object constructs, shaped like a chain, is called a prototype chain.
1 //inheritance, implemented through the prototype chain2 functionBox ()//the inherited function is called the supertype (parent class, base class)3 {4 This. Name = ' Lee ';5 }6 7 functionDesk ()//inherited functions are called subtypes (subclasses, derived classes)8 {9 This. Age =100; Ten } One A functionTable () - { - This. level= ' AAAAA '; the } - - //inherit from the prototype chain, the object instance after the hyper-type instantiation, and assign the prototype attribute to the subtype - //New box will give the information in the box construction and the information in the prototype to desk + //Desk's prototype, got the information in box's Construction + prototype -Desk.prototype =NewBox (); +Table.prototype =NewDesk (); A at varDesk =NewDesk (); -alert (desk.name);//Lee - - varTable =NewTable (); -alert (table.name);//Lee
Javascript-Object-oriented inheritance (1).