I want to pass a class method into a function and call that method inside that function. Here is the code:
class Cube {
constructor() { //setup the cube and if using a previous cube, setup with that
this.white = 'white'
}
changeColour(){
this.white = 'yellow'
}
}
const cubeClass = new Cube()
function change(classMethod){
classMethod()
}
change(cubeClass.changeColour)
I am getting this error:
Cannot read properties of undefined (reading 'white')
I want it to be able to change the colour in the class, from calling the change function, so it can change it from white to yellow