-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.js
45 lines (35 loc) · 1015 Bytes
/
new.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
// NEW Função Construtora que equivale a Classes em Java Script:
/*
function User(nome, email){
this.nome = nome
this.email = email
this.exibirInfos = function(){
return `${this.nome}, ${this.email}`
}
}
const novoUser = new User('Juliana', 'juliana@uol.com')
console.log(novoUser.exibirInfos());
function Admin(role){
User.call(this, 'Juliana', 'juliana@uol.com')
this.role = role || 'estudante'
}
Admin.prototype = Object.create(User.prototype)
const novoUser = new Admin('Admin')
console.log(novoUser.exibirInfos())
console.log(novoUser.role)
*/
// Formato de Objeto:
const user = {
init: function (nome, email){
this.nome = nome
this.email = email
},
exibirInfos: function(nome){
return this.nome
}
}
const novoUser = Object.create(user);
novoUser.init('Juliana', 'juliana@uol.com');
console.log(novoUser.exibirInfos());
//Testar se User esta sendo usado como Protótipo de novoUser:
console.log(user.isPrototypeOf(novoUser));