Skip to content

Commit bdfcbf3

Browse files
SunJieMingSunJieMing
authored andcommitted
Added construtors.js and classes.js
1 parent 84c25eb commit bdfcbf3

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

classes.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// to test these problems you can run 'node classes.js' in your terminal
2+
3+
// problem #1
4+
// convert the Animal constructor function from 'constructors.js' into an ES6 class
5+
6+
7+
// problem #2
8+
// convert the Cat constructor function from 'constructors.js' into an ES6 class
9+
10+
11+
// if everything is setup properly the code below will print 'Foofie grew larger!'
12+
// uncomment the code below to test your solution
13+
14+
// const foofie = new Cat({
15+
// name: 'foofie',
16+
// });
17+
//
18+
// foofie.grow();
19+

constructors.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// to test these problems you can run 'node constructors.js' in your terminal
2+
3+
// problem #1
4+
// add a method to Animal's prototype called 'grow'
5+
// when 'grow' is invoked log '<name> grew larger!'
6+
7+
function Animal(options) {
8+
this.name = options.name;
9+
}
10+
11+
// add 'grow' to Animal's prototype here
12+
13+
// problem #2
14+
// setup Cat to inherit from Animal
15+
// the Animal constructor needs to be invoked with the 'options' argument
16+
// Cat should have its prototype inherit from Animal
17+
// instances of Cat should also have access to the 'grow' method
18+
19+
function Cat(options) {
20+
// invoke Animal here with .call
21+
}
22+
23+
// connect the prototypes here
24+
25+
// if everything is setup properly the code below will print 'Foofie grew larger!'
26+
// uncomment the code below to test your solution
27+
28+
// const foofie = new Cat({
29+
// name: 'foofie',
30+
// });
31+
//
32+
// foofie.grow();
33+

0 commit comments

Comments
 (0)