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.html
in Chrome or Firefox - A bunch of failing tests will show up--please fix them! The first test starts in
src/Student.js
and all of the test specs are in thespecs
folder. The files you need to modify are all in thesrc
folder.
Please do everything in ES6.
- Create a Student class with:
- an
age
property with a value of18
- a
food
property with a value ofcupnoodle
- a
drink
property with a value ofhighball
- a
work
method that returns'study study study'
- a
clothing
property with a value of'tshirt'
- an
- Create a Shinsotsu class with:
- the Student superclass
- an
age
property with a value of22
- a
food
property with a value oframen
- a
drink
property with a value ofbeer
- a
work
method that returns'work work work'
- a
clothing
property with a value ofblack suit
- Create a BossSalaryMan class with:
- the Shinsotsu superclass
- an
age
property with a value of40
- a
food
property with a value ofsushi
- a
drink
property with a value ofsake
- a
wallet
property with a value of100
- a
work
method that returns'yell yell drink drink'
- a
makeMoney
method that adds 10 to the boss's wallet
- Create a WorkerSalaryMan class with:
- the Shinsotsu superclass
- an
age
property with a value of40
- a
food
property with a value ofudon
- a
drink
property with a value ofcansake
- a
wallet
property with a value of50
- a
work
method that returns'work work drink drink'
- a
makeMoney
method that adds 5 to the worker's wallet - a
karaoke
method 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
age
property with a value of70
- a
food
property with a value ofsoba
- a
drink
property with a value oftea
- a
wallet
property with a value of75
- a
work
method that returns'sleep drink gamble sleep'
- a
getPension
method that adds 2 to the salaryman's wallet - a
gamble
method 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