I have this piece of code:
class MyClass {
constructor(text, pattern) {
this.text = text;
this.pattern = pattern;
}
run() {
return this.text.replace(/(\d)/, this.replacer)
}
replacer(match, timeString, offset, string) {
return this.pattern;
}
}
It is a simplified example of my actual code.
When I run:
var v = new MyClass("text 1 2", "X");
v.run();
I see the error:
Uncaught TypeError: Cannot read properties of undefined (reading 'pattern')
How can access to this
in this replacer function?