Is there a technique where I can execute code after a return? I want to return a value then reset the value without introducing a temporary variable.
My current code is:
var foo = (function(){
  var b;
  return {
    bar: function(a) {
        if(b){
          var temp = b;
          b = false;
          return temp;
        }else{
          b = a;
          return false;
        };
    }
  };
})();
foo.bar(1);
I want to avoid the temp var. Is that possible?
var b holds a value between function calls because it is a memoization styled function.
Use a finally block to ensure certain code runs after another block. That block can include errors, returns, or whatever else. The finally block will run after.
try {
    return 'something';
} finally {
    // your after return code
} 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With