Today we will be having fun with ES6 classes while following the lifecycle of the salaryman in detail. You'll create many salarymen today, practicing ES6 instantiation pattern and inheritance.
Today we will diagram the evolution of a salaryman using code. All salarymen begin as fresh students, ready for life as a worker!
Then they progress to new grads and are eventually made either bosses or workers. After a few years, they retire.
- Student
- Shinsotsu
- BossSalaryMan
- WorkerSalaryMan
- RetiredWorkerSalaryMan
- Shinsotsu
Better picture of structure---

- Download the repository of files from GitHub
- Open up
MochaChaiTestRunner.htmlin Chrome or Firefox - A bunch of failing tests will show up--please fix them! The first test starts in
src/Student.jsand all of the test specs are in thespecsfolder. The files you need to modify are all in thesrcfolder.
Please do everything in ES6.
- Create a Student class with:
- an
ageproperty with a value of18 - a
foodproperty with a value ofcupnoodle - a
drinkproperty with a value ofhighball - a
workmethod that returns'study study study' - a
clothingproperty with a value of'tshirt'
- an
- Create a Shinsotsu class with:
- the Student superclass
- an
ageproperty with a value of22 - a
foodproperty with a value oframen - a
drinkproperty with a value ofbeer - a
workmethod that returns'work work work' - a
clothingproperty with a value ofblack suit
- Create a BossSalaryMan class with:
- the Shinsotsu superclass
- an
ageproperty with a value of40 - a
foodproperty with a value ofsushi - a
drinkproperty with a value ofsake - a
walletproperty with a value of100 - a
workmethod that returns'yell yell drink drink' - a
makeMoneymethod that adds 10 to the boss's wallet
- Create a WorkerSalaryMan class with:
- the Shinsotsu superclass
- an
ageproperty with a value of40 - a
foodproperty with a value ofudon - a
drinkproperty with a value ofcansake - a
walletproperty with a value of50 - a
workmethod that returns'work work drink drink' - a
makeMoneymethod that adds 5 to the worker's wallet - a
karaokemethod that subtracts 2 from the worker's wallet and returns'Near, far, wherever you are, I believe that the heart does go on'
- Create a RetiredWorkerSalaryMan class with:
- the WorkerSalaryMan superclass
- an
ageproperty with a value of70 - a
foodproperty with a value ofsoba - a
drinkproperty with a value oftea - a
walletproperty with a value of75 - a
workmethod that returns'sleep drink gamble sleep' - a
getPensionmethod that adds 2 to the salaryman's wallet - a
gamblemethod that subtracts 2 from the salaryman's wallet
- Make new src files for each type of person
- Make corresponding spec files for each type of person
- Link them to
MochaChaiTestRunner.html - Write tests to refactor this to use prototypes
- Refactor Student, Shinsotsu, BossSalaryMan, WorkerSalaryMan, and RetiredWorkerSalaryMan to use prototypes instead of ES6 classes
