We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cd90ea9 commit 5406461Copy full SHA for 5406461
Object_Class.js
@@ -0,0 +1,28 @@
1
+class Person {
2
+ constructor(name, age) {
3
+ this.name = name;
4
+ this.age = age;
5
+ }
6
+
7
+ // Built-in, returns a string by default
8
+ toString() {
9
+ return `This person's name is ${this.name}, ${this.age} years old.`;
10
11
12
+ // Custom function, must be specified in order to call
13
+ Greet() {
14
+ return `Hello there ${this.name}.`;
15
16
+}
17
18
19
+var person1 = new Person("John", 17);
20
+console.log(person1.toString());
21
22
+var person2 = new Person("Jake", 19);
23
+console.log(person2.toString());
24
25
+var person3 = new Person("Blake", 22);
26
+var person3Greeting = person3.Greet(); // Calling the function
27
+console.log(person3Greeting); // Calling the variable
28
0 commit comments