-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise3.js
87 lines (87 loc) · 2.61 KB
/
exercise3.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
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
}
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// Exercise 1 - How was your TypeScript Class?
var Car = /** @class */ (function () {
function Car(name2) {
this.acceleration = 0;
this.name2 = name2;
}
Car.prototype.honk = function () {
console.log("Toooooooooot!");
};
;
Car.prototype.accelerate = function (speed) {
this.acceleration = this.acceleration + speed;
};
return Car;
}());
var car = new Car("BMW");
car.honk();
console.log("Base Acceleration: " + car.acceleration);
car.accelerate(10);
console.log("After Acceleration: " + car.acceleration);
// Exercise 2 - Two objects, based on each other ...
var BaseObject = /** @class */ (function () {
function BaseObject(width, length) {
this.width = 0;
this.length = 0;
this.width = width;
this.length = length;
}
return BaseObject;
}());
;
var Rectangle = /** @class */ (function (_super) {
__extends(Rectangle, _super);
function Rectangle() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rectangle.prototype.calcSize = function () {
return this.width * this.length;
};
return Rectangle;
}(BaseObject));
;
var rectangle = new Rectangle(5, 2);
console.log("rectangle area: " + rectangle.calcSize());
// Exercise 3 - Make sure to compile to ES5 (set the target in tsconfig.json)
var Person2 = /** @class */ (function () {
function Person2() {
this._firstName = "";
}
Object.defineProperty(Person2.prototype, "firstName", {
get: function () {
return this._firstName;
},
set: function (value) {
if (value.length > 3) {
this._firstName = value;
}
else {
this._firstName = "Default";
}
},
enumerable: true,
configurable: true
});
return Person2;
}());
;
var person2 = new Person2();
console.log(person2.firstName);
person2.firstName = "Ma";
console.log(person2.firstName);
person2.firstName = "Maximilian";
console.log(person2.firstName);