In my external JavasScript file (sun.js), I have a class structured like this :
export default class Sun {
constructor(){
this.text = 'I\'m shining!';
}
static testIfShining() {
console.log("is the sun shining?");
console.log(this.text);
}
}
I've imported this class into one of my components
import Sun from '../sun.js'
Then, I invoke the testIfShining()
function within the mounted lifecycle :
mounted() {
Sun.testIfShining();
}
When I check my console, I see the following log message:
is the sun shining?
undefined
The function is functional, but the value of this.text
is displaying as undefined.
How can I access the value set in my constructor across different functions in the class? I want the data to act like an attribute so that it can be reused effectively.