this is summary of my code. Frame is defined as
JavaScript
x
5
1
export type Frame = {
2
changes: readonly vscode.TextDocumentContentChangeEvent[];
3
selections: readonly vscode.Selection[];
4
};
5
record.ts
JavaScript
1
28
28
1
export default class SomeClass {
2
private timeout: NodeJS.Timer | undefined = undefined;
3
private _text = Frame[][] = [];
4
5
constructor() {
6
// Do some constructor
7
}
8
9
private onDidChange() {
10
this.triggerSave();
11
}
12
13
private triggerSave() {
14
if (this.timeout) {
15
clearTimeout(this.timeout);
16
this.timeout = undefined;
17
}
18
19
this.timeout = setTimeout(this.save, 500);
20
}
21
22
private save() {
23
this._text.push('__someframething__');
24
console.log(this._text);
25
// Output: undefined
26
}
27
}
28
on save method, _text must be Frame Thing
But on the console, it’s undefined. what’s wrong with it?
Full code on my gist record.ts buffer.ts
Advertisement
Answer
try:
this.save = this.save.bind(this) in your constructor.
greetings