Execute function on scope exit.