encountered a problem writing publication subscriptions.
I emptied the fns when I called crop.remove (), but there was data to print the fns. Fns.length = 0; this can be cleared. Doesn"t fns also point to this.list [key]?
there are printing results below
let crop = {
list: {},
on(key, fn) {
if(!this.list[key]) {
this.list[key] = [];
}
this.list[key].push(fn);
},
emit(key, ...payload) {
let fns = this.list[key];
if(!fns || fns.length === 0) return;
fns.forEach(fn => {
fn.apply(this, payload);
})
},
remove(key, fn) {
let fns = this.list[key];
console.log(key);
fns = [];
}
}