-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs-classes.js
103 lines (83 loc) · 2.14 KB
/
js-classes.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
class rectangle
{
constructor(width, height, color)
{
this.width = width;
this.height = height;
this.color = color;
console.log(" \nInside constructor. Class members initialised.\n");
console.log("Width = ", this.width);
console.log("Height = ", this.height);
console.log("Color = ", this.color);
}
calcArea()
{
return ((this.width) *(this.height));
}
}
const rect1 = new rectangle(12,12,"yellow");
console.log ("Total area of this rectangle is = ", rect1.calcArea());
*/
/*
class PersonalRecord
{
constructor(firstName,lastName,age,email)
{
this.firstName = firstName;
this.lastName = lastName
this.age = age;
this.email = email;
// console.log("Inside Constructor.\n First name = ", this.firstName, "\n Last name = ", this.lastName, "\n Age = ", this.age, "\n Email = ", this.email);
}
toString()
{
// Maria Petterson (age: 22, email: mp@gmail.com
var str;
str = "\n" + this.firstName + " " + this.lastName + " (age: " + this.age + ", email: " + this.email + ")" ;
return str;
}
}
const pr1 = new PersonalRecord("Steffi", "Graph", 40, "Steffi@gmail.com");
// console.log(pr1.toString());
//var pr_arr= new PersonalRecord ([], [], [], []);
const pr2= new PersonalRecord ("Lexicon","",null , "");
const pr3= new PersonalRecord ("Stefan","Larsson",25 , "");
const pr4= new PersonalRecord ("Peter","Jansson", 24, "ptr@live.com");
const pr5= new PersonalRecord ("Maria","Petterson",22 , "mp@gmail.com");
let people = [];
people.push (pr2); people.push (pr3); people.push (pr4); people.push (pr5);
for (i=0;i<4;i++) console.log(people[i]);
*/
/*
class circle
{
constructor(radius)
{
this.radius = radius;
}
get radius()
{
}
set radius()
{
}
}
*/
class point
{
constructor (x,y)
{
this.x = x;
this.y = y;
}
static distance(o1, o2)
{
let dx = o2.x - o1.x;
let dy = o2.y - o1.y;
return Math.sqrt(dx*dx +dy*dy);
}
}
var p1 = new point(5,5);
var p2 = new point(9,8);
console.log(point.distance(p1, p2));