-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascriptclasses.js
More file actions
36 lines (30 loc) · 973 Bytes
/
javascriptclasses.js
File metadata and controls
36 lines (30 loc) · 973 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
// How to create Classes in ES6
// 1. we can create class declaration
// 2. class expression
// Class declaration
// takes number of methods but use constructor() method for every class
// Every Class must have a constructor, this is how you build the object properties
// the constructor every property that is going to be on an object you need to drop a pramater for it
// to create a method use the shorthand
class Person {
constructor(name, hobby) {
this.name = name;
this.hobby = hobby;
}
greeting() {
console.log(`Hello my name is ${this.name}`);
}
myHobby() {
console.log(`My fav hobby is ${this.hobby}`);
}
// static method and lives on actual person object itself
// Person.saySomething() makes this work
static saySomething() {
console.log('Coding is so cool!');
}
};
// Class Expression
// const Person = class {
// }
const person1 = new Person('Jack', 'Coding');
const person2 = new Person('Jill', 'Skydiving');