something like stackbased objects in c++ for javascript
问题 Looking for a construct in javascript which works like the destructor in stackbased or local object in c++, e.g. #include <stdio.h> class M { public: int cnt; M() {cnt=0;} void inc() {cnt++;} ~M() {printf ("Count is %d\n", cnt);} }; ... {M m; ... m.inc (); ... m.inc (); } // here the destructor of m will printf "Count is 2"); so this means I am looking for a construct which does an action when its scope is ending (when it "goes out of scope"). It should be robust in the way that it does not