Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // You don't need the constructor if you use initializers on the fields:
- class SW {
- private startTime: number = 0;
- // −−−−−−−−−−−−−−−−−−−−−−^^^^
- private endTime: number = 0;
- // −−−−−−−−−−−−−−−−−−−−^^^^
- start() {
- this.startTime = Date.now();
- }
- stop() {
- this.endTime = Date.now();
- }
- getDuration() {
- const seconds = (this.endTime - this.startTime) / 1000;
- }
- }
- // In fact, if you do that, you don't even need to write the type explicitly
- // because TypeScript will infer `number` from the initializer
- class SW {
- private startTime = 0;
- // −−−−−−−−−−−−−−^^^^
- private endTime = 0;
- // −−−−−−−−−−−−^^^^
- start() {
- this.startTime = Date.now();
- }
- stop() {
- this.endTime = Date.now();
- }
- getDuration() {
- const seconds = (this.endTime - this.startTime) / 1000;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement