function test() { return new Promise(function (success, error) { if(1 > 0) { success(true); }else{ error(false); } }); } var check; test().then( check = true, check = false ); console.log(check);
test().then( function() {check = true}, function() {check = false} );
<script src="https://cdnjs.cloudflare.com/ajax/libs/co/4.1.0/index.min.js"></script> <script> function test() { return new Promise(function (success, error) { if(1 > 0) { success(true); }else{ error(false); } }); } co(function* (){ var check; check = yield test(); alert(check); }).catch(e => alert(e)) </script>
var check; console.log(check = true);