-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOOPS.js
62 lines (51 loc) · 1.38 KB
/
OOPS.js
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
/*---------------------------------------------------------
author: kallol chakraborty
program no: 015
program description: OOP Practice
time complexity:
space complexity:
date: 29/11/2021
----------------------------------------------------------*/
// methods are functions within objects in OOP
// better way of declaring objects
let circle = {
radius: 1,
location: {
x: 1,
y: 1
},
isVisible: true,
draw: function () {
console.log('Draw Function is called !');
}
};
// calling the function
circle.draw();
// factory functions to create objects: uses the camel notation
function createCircle(radius) {
return {
radius, // if the parameter and member object is of same name, we can use only the parameter
draw() {
console.log(`Radius is ${radius}`);
}
};
}
// declaring the object
let circle1 = createCircle(5);
// calling the method
circle1.draw();
/*
Camel Notation: oneTwoThreeFour
Pascal Notation: OneTwoThreeFour
*/
// another way of declaring objects
// constructor function : no return statement as it will work under the hood & uses pascal notation
function CircleDraw(radius) {
this.radius = radius,
this.draw = function () {
console.log(`Radius is ${radius}`);
}
}
// creating the objects
const circle2 = new CircleDraw(6);
circle2.draw();