How can I do Inheritance in Reactjs, I am working on canvas based app. I need to create object and extend and add some stuff and events for this I tried to make basic code for example. This is what I have tried but dosen't work, I wanna know what should I do to achieve this
export default function car() {
let speed = 40;
let name = 'basic car'
let engine = {
type: petrol
}
this.run = () => {
console.log(name + ' can run with max ' + speed + 'kmph');
}
this.getinfo = () => {
console.log('this is ' + name + ' which can run using ' + engine.type)
}
this.eve = () => {
//Trigger engine object redux events
}
this.getengine = () => {
return engine
}
}
export default mustang extends car() {
this.speed = 200
this.name = 'ford mustang'
this.engine = {
type 'disel'
}
}
let mycar = new mustang()
mycar.run() // Required output = ford mustang can run with max 200kmph
mycar.getinfo() //Required output = this is ford mustang which can run using disel
mycar.eve() // Require output fordcar engine triggler event
mycar.getengine() // Rquire output ford car disel type engine object
extends.