-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoopConcept.js
More file actions
51 lines (44 loc) · 1.88 KB
/
oopConcept.js
File metadata and controls
51 lines (44 loc) · 1.88 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
// the oops concepts in javascript is different from the oop concept in lower programming languages
// class, methods, objects, and the four pillar of the oop concepts
// 1. encapsulation, inheritance, abstraction and the polymorphism
// now its high time to combine all the concepts into one, that i have learned so far for more than 2 years.
// be the dsa or any other programming concepts, its combine all the concept and start builing all the stuff
// that i wanted to build so bad, i really need to have a strong foundations in everything that i do
// r & d and l, is the main core concept that i really believed in. Now lets rock and roll
/*
class(is like a blue print for the objects, or its act like a template for the objects)
objects(its like a container that holds all the properties of that particular objects)
methods(functions inside the class is called as the methods ty)
constructors(that init the properties of the objects)
// four pillar of the oops concept
1. abstraction
2. inheritance
3. encapsulation
4. polymorphism
*/
// this is the template for the objects that i want to create
class professor {
name;
subject;
salary;
// using the constructor, we should be using the constructor keyword unlike the c++
constructor(name, subject, salary) {
this.name = name;
this.subject = subject;
this.salary = salary;
}
// defining the methods
introduce() {
console.log("Welcome", this.name)
}
}
// creating the objects using the professor, where it will acts as the template for the objects
const tshewang = new professor("tshewang", "chemistry", 1200);
tshewang.introduce();
// the different methods to create a objects in javascript
/*
object literals, const obj ={};
using the constructor functions, that what we do in oops concept, should be using the new keywords
using the Object.create
using the new Object() constructor
*/