let array: any[] = [];
class Test {
constructor() {
// adding a bound method to the array
array.push(this.testMethod.bind(this));
console.log('xxx', array); // expecting [ [Function: bound ] ], actually getting [ [Function: bound ] ]
// removing bound method from the array using filter
array = array.filter(f => f !== this.testMethod.bind(this));
// filter did not work as expected, method still present in the array
console.log('xxx', array); // expecting [], but getting [ [Function: bound ] ]
}
public testMethod(): void {
return undefined;
}
}
I am experimenting with adding and removing bound methods from arrays. Although I used a filter
to remove the method, it seems to persist. Can anyone shed light on a possible scope issue here?