Is there anything like python's `with` statement in javascript?

Viewed 356

A with statement in python is useful for cleaning up resources, e.g.

with open('file.txt', 'w') as f:
   // do something with the file

the writer of the code does not have to worry about closing the file, because writer of the open function has implemented necessary stuff to clean up file resources.

What are the common patterns in javascript to achieve this functionality?

0 Answers
Related