In old javascript class you could create values that would always work, how do you do this in es6 classes?
function B() {
var text = "B"
var self = this // store this so we don't lose it
this.speak = function() {
return alert(self.text)
}
}
var b = new B();
var f = {}
f.pointer = b.speak
f.pointer()
b.speak()
How do you do this in es6?
class A{
constructor() {
this.text = "A";
}
speak(){
alert(this.text) // this is not correct how to fix?>!!
}
}
var a = new A();
var f = {}
f.pointer = a.speak
f.pointer()
a.speak()