This is possible in Python by utilizing the destructor and relying on the fact that Python uses reference counting as its first GC tier:
classlog:# yes this is a class but you can just use it like a function
def__init__(self,text):self.text=textself.print_on_dtor=Truedef__del__(self):ifself.print_on_dtor:self.print_on_dtor=Falseprint('log:',self.text)defwith_data(self,data):self.print_on_dtor=Falseprint('withData:',self.text,data)
JS doesn't have destructors so you can't use that trick there. I'm also not sure if the GC is as predictable as Python's (and with all the various implementations I won't be surprised if it has different rules on different engines...)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is possible in Python by utilizing the destructor and relying on the fact that Python uses reference counting as its first GC tier:
JS doesn't have destructors so you can't use that trick there. I'm also not sure if the GC is as predictable as Python's (and with all the various implementations I won't be surprised if it has different rules on different engines...)