-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodewarsChallenge62.js
More file actions
60 lines (45 loc) · 1.35 KB
/
codewarsChallenge62.js
File metadata and controls
60 lines (45 loc) · 1.35 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
class Vehicle {
constructor(color= 'blue', wheel= 4, horn = 'beep beep') {
this.color = color;
this.wheel = wheel;
this.horn;
}
honkHorn(){
console.log(this.horn)
}
}
//Bicycle subclass
class Bicycle extends Vehicle{
constructor(color){
//Call the parent constructor with overridden value
super(color, 2, 'honk honk');
}
}
//test
const myVehicle = new Vehicle();
myVehicle.honkHorn(); // Output: beep beep
const myBike = new Bicycle();
myBike.honkHorn() // Output: honk honk
/*
function Vehicle(color = 'blue', wheels = 4, horn = 'beep beep'){
this.color = color
this.wheel = wheels;
this.horn = horn;
}
Vehicle.prototype.honkHorn = function(){
console.log(this.horn);
}
// Bicycle Constructor function
function Bicycle(color){
// Call the vehicle constructor with overidden values
Vehicle.call(this, color, 2, 'honk honk'); `this` refers to the new Bicycle instance if you leave the this keyword over there //Vehicle.call(); // Incorrect - does not associate properties with new instance
}
// Inherit from Vehicle
Bicycle.prototype = Object.create(Vehicle.prototype);
Bicycle.prototype.constructor = Bicycle; //is adjusted to point back to Bicycle.
// Test
const myVehicle = new Vehicle();
myVehicle.honkHorn()
const myBike = new Bicycle();
myBike.honkHorn();
*/