Skip to main content
100%

inheritance-2.js

✓ Published0🌍 Public
Aalessioalex
Last edited Nov 22, 2014
Created on Nov 22, 2014

This example demonstrates JavaScript prototype-based inheritance by defining a Person constructor with a getInfoCard method, then creating a Student subclass that inherits from Person via `Object.create(Person.prototype)` and calls `Person.call(this, name, age)` to reuse the parent constructor. The code shows how Student instances, created with the `new` keyword, pass `instanceof Person` checks and access inherited methods like `getInfoCard`, while also adding their own `getName` method. It uses no external libraries, relying solely on native JavaScript constructors, prototypes, and object creation to illustrate classical-style inheritance patterns.

AI-generated description

Similar vizzes