O'Reilly logo

Learning Angular for .NET Developers by Rajesh Gunasundaram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inheritance

Inheritance is the concept of inheriting some behaviors of another class or object. It helps achieve code reusability and build hierarchy in relationships of classes or objects. Also, inheritance helps you cast similar classes.

JavaScript of ES5 standard doesn't support classes, and so, class inheritance is not possible in JavaScript. However, we can implement prototype inheritance instead of class inheritance. Let's see inheritance in ES5 with examples.

First, create a function named Animal, as follows. Here, we create a function named Animal with two methods: sleep and eat:

var Animal = function() {     this.sleep = function() {        console.log('sleeping');     }     this.eat = function() {        console.log('eating');     } } 

Now, let's extend ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required