Nevermind if you disapprove what I'm doing seems overcomplicated but it's an experiment to undersyand, my question here is only about syntax : I can't see what's wrong since https://jsfiddle.net/tx2ac6kq/28/ outputs no error but I should have log from checkText and I don't get any :
class Test {
#text;
set text(text) {
this.#text = text;
}
get text() {
console.log("get text")
let value = (async () => await new Promise(resolve => {
let timerId = setInterval(checkText, 1000);
checkText = () => {
console("check")
let value = this.#text;
console.log(value);
if (value) {
clearInterval(timerId);
resolve(value);
}
else {
console.log("checkText");
reject("checkText rejected");
}
}
}))();
}
constructor() {
fetch("https://jsonplaceholder.typicode.com/posts/1")
.then((response) => {
response.text().then((response) => {
//console.log("response", response);
this.text = response;
console.log("this.text", this.#text);
});
});
}
}
let test = new Test();
let value = test.text;