The prototype chain and property shadowing

When we try to access a property or a method of an object, the runtime will search for that property or method in the object's properties and methods. If it is not found, the runtime will continue searching through the object's inherited properties by navigating the entire inheritance tree. Because a derived object is linked to its base object through the prototype property, we refer to this inheritance tree as the prototype chain.

Let's look at an example. We will declare two simple TypeScript classes named Base and Derived:

class Base { 
    public method1() { return 1; } 
    public method2() { return 2; } 
} 
 
class Derived extends Base { 
    public method2() { return 3; } 
    public method3() { return 4; } 
} 

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.