closures - how to terminate parent function execution in javascript? -


i need override behaviour of function, goes after calls other function. problem parent function library , dont want change it, solutions make flag or change of function not good. know got caller object in function can change, maybe can figure out smth it. heres example:

function parent() {   console.log("some need stuff");   some.handler.function.from.config.that.i.can.change();   console.log("need omit right till end"); }  function child() {   console.log("need somehow stop evaluation of " + child.caller + " function"); } 

as ruby programmer know there lambdas can terminate evaluation inner scope of closure. im not sure how javascript.

you can't directly. (moreover .caller obsolete)

you can use dirty trick:

try{     parentfunction();//calls child }catch(e){    //done }  function child(){     dowhatever();     throw new error("this propagate"); } 

fiddle

this work assuming parent not catch exceptions when calling child.

moreover, bad idea use exceptions flow control. use last resort.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -