Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<meta name="description" content="73 - Deferreds" />
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <br />
  <button id="btnResuelve">Resolver</button>
  <button id="btnRechaza">Rechazar</button>
  <button id="btnEstado">¿Estado?</button>
  
</body>
</html>
 
var promesa = $.Deferred();
promesa.done(function() {
    console.log("Se ejecutará cuando la promesa se resuelva.");
});
promesa.fail(function() {
    console.log("Se ejecutará cuando la promesa se rechace.");
});
promesa.always(function() {
    console.log("Se ejecutará en cualquier caso.");
});
/*
promesa.then(function() {
    console.log("Se ejecutará cuando la promesa se resuelva.");
}, function() {
    console.log("Se ejecutará cuando la promesa se rechace.");
}, function() {
    console.log("Se ejecutará en cualquier caso.");
});
*/
$("#btnResuelve").click(function() {
  promesa.resolve();
});
$("#btnRechaza").click(function() {
  promesa.reject();
});
$("#btnEstado").click(function() {
 console.log(promesa.state());
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
aitormedran0pro
0viewers