Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this sample code, there is a Person object and from the Person object, a Student object is derived. As we can see in this

In this sample code, there is a Person object and from the Person object, a Student object is derived.

As we can see in this example, the initialize method belongs to Person and the learn method belongs to Student, both of which are now part of the me object.

Keep in mind that there are many ways of doing inheritance in JavaScript, and this is just one of them.

Exercise Create an object called Teacher derived from the Person class, and implement a method called teach which receives a string called subject, and prints out:

[teacher's name] is now teaching [subject] JavaScript Programming

var Person = function() {}; Person.prototype.initialize = function(name, age) { this.name = name; this.age = age; } Person.prototype.describe = function() { return this.name + ", " + this.age + " years old."; } var Student = function() {}; Student.prototype = new Person(); Student.prototype.learn = function(subject) { console.log(this.name + " just learned " + subject); } var me = new Student(); me.initialize("John", 25); me.learn("Inheritance");

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

What geometrical shape is used to define clusters in k - Means?

Answered: 1 week ago

Question

=+ 5. Do Europeans work more or fewer hours than Americans?

Answered: 1 week ago