-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex-29-prototype.js
More file actions
43 lines (32 loc) · 872 Bytes
/
ex-29-prototype.js
File metadata and controls
43 lines (32 loc) · 872 Bytes
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
'use strict';
//classe animal e quantidade de pernas
//metodo andar imprimir andando com a quantidade de pernas
//criar três animas, casa um com uma forma diferente de setar o prototipo
var pernas = {
qtdPernas: 4,
andar: function(){
return `${this.animal} Andando com ${this.qtdPernas} pernas!` //se utilizasse o EC06
//modo normal seria: this.animal + ' anda com ' + this.qtdPernas + ' pernas!';
}
};
//PROTO
var animal01 = {
animal: 'Jacaré',
__proto__: pernas
};
console.log(animal01.andar());
//CREATE
var animal02 = Object.create(pernas);
animal02.animal = 'Aranha';
animal02.qtdPernas = 8;
console.log(animal02.andar());
//PROTOTYPE_OF
var animal03 = {
animal: 'Cobra',
andar: function() {
console.log('Cobra não anda!');
}
};
Object.setPrototypeOf(animal03, pernas);
animal03.qtdPernas = 0;
console.log(animal03.andar());