-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototype.js
More file actions
39 lines (33 loc) · 776 Bytes
/
prototype.js
File metadata and controls
39 lines (33 loc) · 776 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
// Prototype
class TeslaCar {
constructor(model, price, interior, autopilot) {
this.model = model
this.price = price
this.interior = interior
this.autopilot = autopilot
}
produce() {
return new TeslaCar(this.model, this.price, this.interior, this.autopilot)
}
}
const prototypeCar = new TeslaCar('S', 80000, 'black', false)
const car1 = prototypeCar.produce()
const car2 = prototypeCar.produce()
const car3 = prototypeCar.produce()
car1.interior = 'white'
car1.autopilot = true
// console.log(car1)
// {
// "model": "S",
// "price": 80000,
// "interior": "white",
// "autopilot": true
// }
// console.log(car2)
// {
// "model": "S",
// "price": 80000,
// "interior": "black",
// "autopilot": false
// }
// console.log(car3)