Skip to content

Commit ad1f233

Browse files
committed
Merge pull request #1 from joshbivens/joshbivens-patch-1
Add simple class example
2 parents b8b8cb0 + 0184a60 commit ad1f233

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

class.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
/**
22
* Class is a syntactical sugar over prototype based inheritance.
33
*/
4+
class Animal {
5+
constructor(type, sound) {
6+
this.type = type;
7+
this.sound = sound;
8+
}
9+
10+
makeNoise() {
11+
return ('The' + this.type + ' goes ' + this.sound);
12+
}
13+
}
414

5-
//TODO -- Write a simple example for classes
15+
var Simone = new Animal("cat", "meow");
16+
17+
Simone.makeNoise(); // returns "The cat goes meow"

0 commit comments

Comments
 (0)