-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathclasses.js
More file actions
47 lines (36 loc) · 983 Bytes
/
classes.js
File metadata and controls
47 lines (36 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// to test these problems you can run 'node classes.js' in your terminal
// problem #1
// convert the Animal constructor function from 'constructors.js' into an ES6 class
class Animal {
constructor(options) {
this.name = options.name;
}
grow() {
return `${this.name} grew larger!`
}
}
//NEW STYLE
// class Foo {
// constructor(x) {
// this.x = x;
// this.y = 432;
// }
// point() {
// return 'Foo(' + this.x + ', ' + this.y + ')';
// }
// }
// let myfoo = new Foo(99);
// console.log(myfoo.point()); // prints "Foo(99, 432)"
// problem #2
// convert the Cat constructor function from 'constructors.js' into an ES6 class
class Cat extends Animal{
constructor(options) {
super(options);
}
}
// if everything is setup properly the code below will print 'Foofie grew larger!'
// uncomment the code below to test your solution
const foofie = new Cat({
name: 'foofie',
});
foofie.grow();