javascript - wrap if else statement as function -


suppose have following if else statement code.

if (checkvalue(3)) {     dofunction(); } else {     alert('fail'); }  function checkvalue(value) {     return value; } 

and want convert following return same result.

checkvalue(3, dofunction()); 

how can done?

note: not want repeat if else because use multiple times in code. neither want use ternary operator

use callback this

function checkvalue(value, cb) {     if (value) {         cb(value);     } else {         alert('fail')     } }  checkvalue(3, dofunction); 

note: don't pass dofunction(), want pass function, not result of calling function


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -