In this assignment, we'll implement and test a stack:
- Implement a stack class
- Throughly test the functionality of your stack.
-
Run the (mostly empty) test suite
- This repo contains a mostly empty Mocha test suite. To run it, open up
SpecRunner.html
.
- This repo contains a mostly empty Mocha test suite. To run it, open up
-
Refactor your stack to use the following methods of instantiation:
- Functional instantiation: a simple "maker" pattern (This is already done!)
- Do:
- Work within the
src/functional/
folder. - Define all functions and properties within the maker function.
- Work within the
- Don't:
- Use the keyword
new
, the keywordthis
, or anyprototype
chains. - Capitalize the maker function name.
- Use the keyword
- Example: The provided class
makeStack
already follows this pattern
- Do:
- Functional instantiation with shared methods: same as step 1, but with shared methods
- Do:
- Work within the
src/functional-shared/
folder. - Create an object that holds the methods that will be shared by all instances of the class.
- You'll need to use the keyword
this
in your methods. - Use
_.extend
to copy the methods onto the instance.
- Work within the
- Don't:
- Use the keyword
new
orprototype
chains
- Use the keyword
- Example: functional instantiation example
- Do:
- Prototypal instantiation: using
Object.create
- Do:
- Work within the
src/protoypal/
folder. - Use
Object.create
with the object from step 2 to create instances of your class
- Work within the
- Don't:
- Use the keyword
new
- Use the keyword
- Example: prototypal instantiation example
- Do:
- Pseudoclassical instantiation: create instances with the keyword
new
- Do:
- Work within the
src/pseudoclassical/
folder. - Capitalize your function name to indicate that it is intended to be run with the keyword
new
- Use the keyword
new
when instantiating your class - Use the keyword
this
in your constructor
- Work within the
- Don't:
- Declare the instance explicitly
- Return the instance explicitly
- Example: pseudoclassical instantiation example
- Do:
- Functional instantiation: a simple "maker" pattern (This is already done!)
- Use the Chrome profiling tools to compare the performance of each instantiation pattern.
- Create a profiling test case in each of your test suites. It should instantiate and use a large number of stacks.
- Comment out all but one test suite. Record the results of the profiler. Repeat for each step of the refactor.
- Write a brief analysis of your results.
Copyright 2013, Hack Reactor, LLC. All rights reserved.