I wish, I could write elegant two of the code pattern I use frequently.

Patten 1.
HTML button click event handler should always return false (ie, when
you never want the submit action).
So I always write.

function someClickHandler(){
  try {
    doStuff();
    doAnotherStuff();
    doYetAnotherStuff();
  } catch(e){
  }
  return false;
}


Patten 2.
I do like to code functions with early exit, like

function someValidationProcess(){

    doStuff();
    if(condition_1()){
        doCleanUp_1();
        doCleanUp_2();
    }

    doAnotherStuff();
    if(condition_2()){
        doCleanUp_1();
        doCleanUp_2();
     }

    doYetAnotherStuff();
    if(condition_3()){
        doCleanUp_1();
        doCleanUp_2();
     }

    doMoreStuff();
    doCleanUp_1();
    doCleanUp_2();
}


Proposal:
I wish there was some syntax sugar like

function someClickHandler(){
    doStuff();
    doAnotherStuff();
    doYetAnotherStuff();
} finally {
   return false;
}


function someValidationProcess(){

    doStuff();
    breakif(condition_1());

    doAnotherStuff();
    breakif(condition_2());

    doYetAnotherStuff();
    breakif(condition_3());

    doMoreStuff();

} finally {
    doCleanUp_1();
    doCleanUp_2();
}


Cheers
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to