Objective: Model functionality for an apartment rental app using JavaScript object constructors, prototypes, and inheritance.
- Implement constructors and prototype methods for
Person
,Manager
,Tenant
,Apartment
, andUnit
(see starter code in those files). - Implement prototypal inheritance for the following:
Manager
inherits fromPerson
Tenant
inherits fromPerson
- Make sure all tests are passing (to run tests, type
npm test
in your Terminal).
-
Create a new file
src/inherits.js
and implement aninherits
function:var inherits = function(Child, Parent) { Child.prototype = new Parent(); Child.prototype.constructor = Child; }; module.exports = inherits;
Then require the
inherits
module in each file that require inheritance, and use theinherits
function to DRY up your code. -
Write more tests! You'll find some simple tests in the
test
sub-directory. Once you have all the tests passing, try adding a couple more for edge cases. For example:- What happens if you try to add a tenant to a unit that's not available?
- What if a tenant tries to move in without any references?
-
Fork this repo, and clone it into your
develop
folder on your local machine. -
Change directories into
apartment-oop
, and runnpm install
in your Terminal. This installs the testing modules (mocha
andchai
) locally into your project repo. -
Instructions for implementing each module are in their respective files, so poke around in
person.js
,manager.js
,tenant.js
,apartment.js
, andunit.js
. Read the comments to guide your implementation.
The main.js
file is set up to allow you to test your models in the node REPL.
-
Open the node REPL and
require('./src/main.js')
:โ node > var app = require('./src/main.js');
-
Create a new instance of
Person
:> var Person = app.Person; > var john = new Person('John Doe', '123-456-7890'); > john.contact '123-456-7890'
- As you make code changes, frequently commit and push to GitHub.
- Once you've finished the assignment and pushed your work to GitHub, make a pull request from your fork to the original repo.