JavaScript supports object-oriented programming, but using a different mechanism.

Encapsulation

Encapsulation is implemented in JavaScript using functions, properties and nested functions.

Exercise 2.1

Build an object prototype for a person that includes features for maintaining or computing the following. Use ES5 constructs for this exercise (i.e., not ES6, aka ES2015, constructs).

Add some code to test your new prototype, e.g., create some instances, add friends, compare ages.

Inheritance and Polymorphism

Prototype-based languages can implement inheritance and polymorphism as well.

Exercise 2.2

Build an object prototype for a student that inherits the features of the person class and adds the following.

Add some code to test your new child prototype, e.g., create some instances, check the sub-classing using the instanceof operator and demonstrate the inherited/polymorphic methods.

Checking in

Submit your code under the directory lab02. We will grade your work according to the following criteria:

All code will be submitted using GitHub, so, if haven’t already done so, create a GitHub account, add a new repo for this course and add your new lab02 directory. Remember to submit your GitHub ID as specified in the forum posting on this subject. We also suggest that you add a .gitignore file to root directory of your repo (see the example in the cs336-code repo.