I have the following sample code. I'm trying to get the this.key
inside the namespace function but it's always returning undefined despite me changing the function call, or using arrow approach etc.
class Sample {
key = '';
constructor(key) {
this.key = key;
}
myNamespace = {
saySomething: function(message) {
console.log('message:', message);
console.log('key:', this.key);
}
}
getTheKey() {
console.log('key', this.key);
}
}
let sample = new Sample('thekey');
sample.myNamespace.saySomething('message'); // shows-> key: undefined
sample.getTheKey(); // shows-> key: thekey