-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclasses.js
More file actions
90 lines (59 loc) · 2.05 KB
/
classes.js
File metadata and controls
90 lines (59 loc) · 2.05 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//* ES6 Classes
//? ==> Object-Oriented Programing(OOPs)
// 3 Pillars of OOPs
//? Object, Class, Methods
// The class contains the Constructors and functions
// The Constuctors take responsibility for allocating memory for the objects of class.
// The function takes the responsibility of the action of the object. Combing these two Constructor and Function to make the Class
//* => class Declaration
// to declare a class, you use the class keyword with the name of the class
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
}
//* => Hoisting
// An Important difference between function declaration and class declaration is that while functions can be called in Code that appears before they are defined, classes must be defined before they can be constructed
//* => Class Expressions
// A class expression in another way to define a class.
//! unnamed expression
let Rectangle = class {
constructor(height, width) {
this.height = height;
this.width = width;
}
};
console.log(Rectangle.name); // Rectangle
//! named expression
let Rectangle = class Rectangle2 {
constructor(height, width) {
this.height = height;
this.width = width;
}
};
console.log(Rectangle.name); // Rectangle2
//* class inheritance
// the es6 class supports the inheritance. Inheritance has the courage to create entities from exiting entities. There are two types of class in ES6;
// -> Parent class/super class
// The class extended to create new class are know as a parent class or super class.
// -> Chid/sub classes
// The class are newly created are know as child or sub class. Sub class inherit all the properties from parent class except constructor.
//* Class inheritance Example
class Student {
constructor(a) {
this.name = a;
}
}
class User extends Student {
show() {
console.log(this.name);
}
}
var obj = new User("Rogers");
obj.show(); // Rogers
//? ==> Type of inheritance
//* Single Level Inheritance
// Class A <== Class B
//* Multi Level inheritance
// Class A <== Class B <== Class C