-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-classes.js
More file actions
57 lines (42 loc) · 1.1 KB
/
Copy pathscript-classes.js
File metadata and controls
57 lines (42 loc) · 1.1 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
class Book {
constructor(title, author, pages) {
this.title = title;
this.author = author;
this.pages = pages;
}
read() {
return `Estou lendo ${this.title}`;
}
}
let book = new Book('Algoritmos para viver', 'Brian', 500);
console.log(book);
console.log(book.read());
let otherBook = new Book( 'Um Exu em Nova York', 'Cidinha da Silva', 100 )
console.log(book, otherBook)
class ITBook extends Book {
constructor(title, author, pages, technology) {
super(title, author, pages);
this.technology = technology;
}
}
let itBook = new ITBook('Código Limpo', 'Robert Cecil', 500, 'Algoritmos');
console.log(itBook)
console.log(itBook.title);
console.log(itBook.read());
// Conceito de encapsulamento
console.log( '\n + ### Conceito de encapsulamento ###');
class Person {
constructor(name) {
this._name = name;
}
get name() {
return this._name;
}
set name(value) {
this._name = value;
}
}
var person = new Person('Fabio');
console.log(person.name);
person.name = 'Biones';
console.log(person.name);