Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
JavaScript Projects for Kids

You're reading from   JavaScript Projects for Kids Gear up for a roller-coaster ride into the world of JavaScript and programming with this easy-to-follow, fun, and entertaining project-based guide

Arrow left icon
Product type Paperback
Published in Jan 2016
Publisher Packt
ISBN-13 9781785287176
Length 188 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
 Omar Faruk Towaha Omar Faruk Towaha
Author Profile Icon Omar Faruk Towaha
Omar Faruk Towaha
Arrow right icon
View More author details
Toc

Inheritance in JavaScript


To inherit means derive something (such as, characteristics, quality, and so on) from one's parents or ancestors. In programming languages, when a class or object is based on another class or object in order to maintain the same behavior of the parent class or object is known as inheritance.

We can also say that this is a concept of gaining properties or behaviors of something else.

Suppose, X inherits something from Y; it is like X is a type of Y.

JavaScript occupies the inheritance capability. Let's take a look at an example. A bird inherits from an animal as a bird is a type of animal. Therefore, a bird can do the same thing that an animal does.

This kind of relationship in JavaScript is a little complex and needs a syntax. We need to use a special object called prototype, which assigns the properties to a type. We need to remember that only function has prototypes. Our Animal function should look similar to the following:

function Animal(){
//We can code here. 
...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images