-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
48 lines (45 loc) · 1019 Bytes
/
script.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
//example 1
class Car {
constructor(brand, color) {
this.brand = brand; // key = value
this.color = color;
}
printcolor(str) {
return str + this.color;
}
}
var test = new Car("Audi", "black");
var result = test.printcolor("the color of my car is ");
console.log(result);
//example 2
class Circle {
constructor(radius, color) {
this.radius = radius;
this.color = color;
}
get radiusCircle() {
return this.radius;
}
get colorCircle() {
return this.color;
}
set radiusCircle(radius) {
this.radius = radius;
}
set colorCircle(color) {
this.color = color;
}
get toString() {
return `"Circle[radius=${this.radius}, color=${this.color}]"`;
}
get areaCircle() {
return Math.PI * this.radius * this.radius;
}
get circumferenceCircle() {
return 2 * Math.PI * this.radius;
}
}
var obj1 = new Circle(1.0, "red");
console.log(obj1.radiusCircle); //get radiusCircle
obj1.radiusCircle = 2.2;
console.log(obj1.radiusCircle); //set radiusCircle