This repository was archived by the owner on Jul 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.js
More file actions
65 lines (51 loc) · 1.39 KB
/
inheritance.js
File metadata and controls
65 lines (51 loc) · 1.39 KB
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
'use strict';
class Task {
constructor(title) {
this._title = title;
this._done = false;
Task.count += 1;
console.log(`The task is initialized : "${this._title}"`);
}
complite() {
this.done = false ;
console.log(`${this._title} complited.`);
}
get done() {
return this._done ? `The ${this._title} is complited` : 'Wasted'
}
set done(v) {
if (typeof this._done === 'boolean') this._done = v;
else console.log('type true or false')
}
get title() {
return this._title
}
set title(v) {
if(typeof v === 'String')this._title = v
}
static getDefaultTitle() {
return 'The task'
}
}
Task.count = 0;
class SubTask extends Task {
constructor(title,parent) {
super(title);
this.parent = parent;
}
complite() {
super.complite();
console.log(`Subtask '${this._title}' is complited`);
}
}
// Usage
const task = new Task('Learn inheritance in JS');
const subtask = new SubTask('Learn inheritance in ES6',Task);
// console.log(task.title);
// console.log(subtask.title);
// subtask.title = 'New title';
// console.log(subtask.title);
console.log(`Tasks count = ${SubTask.count}`);
console.log(`The DefaultTitle is '${SubTask.getDefaultTitle()}'`);
subtask.complite();
console.log(`Status : ${subtask.done}`);