1
I’m implementing a chain of responsabilities
, and, when the desired object is returned, it continues with the instances of the items after it:
const ITEM_SELECIONADO = "EXEMPLO"
export interface ChainModelo{
setNext(modelo: ChainModelo);
next();
}
export class ExemploChain{
modelo: ChainModelo | null;
name:string = 'EXEMPLO';
setNext(modelo: ChainModelo){
this.modelo = modelo;
}
next(){
if(ITEM_SELECIONADO !== name)
return modelo.next();
return this;
}
}
In short, instances of various useless objects are stored in memory until the object is destroyed. To get around the problem, I modified the method next
to possess the following behaviour:
next(){
if(ITEM_SELECIONADO !== name)
return modelo.next();
this.modelo = null;
return this;
}
But what I wanted was for this property to be destroyed, that it could no longer be accessed, as if it didn’t even exist. There is a way to remove a property or behavior from an object in Typescript or Javascript?
delete this.modelo
– bfavaretto
That’s exactly it, thank you.
– Arthur Siqueira
Put in an answer, then close the question
– Arthur Siqueira
You also have other options: deleting property with Slice, from its position or simply setting it to
this.modelo = undefined;
.– Ivan Ferrer