Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>Pub/Sub with Deferred and Promise</title>
</head>
<body>
  <script>
    (function($) {
      // Deferred objects for our app states
      var start = new $.Deferred(),
          finish = new $.Deferred();
      
      window.Utils = {
        start: start.promise(),   // Only expose the Promise of each
        finish: finish.promise()  // " " " " " "
      };
      
      $(function() {
        alert("Calling funcs...");
        // Start the app
        start.resolve();
        // Finish the app (or whatever)
        finish.resolve();
      });
      
    })(jQuery);
  </script>
  <script>
    // Module 1
    Utils.start.then(function() {
      alert("Module 1 Started!");
    });
    Utils.finish.then(function() {
      alert("Module 1 Finished!");
    });
  </script>
  <script>
    // Module 2
    Utils.start.then(function() {
      alert("Module 2 Started!");
    });
    Utils.finish.then(function() {
      alert("Module 2 Finished!");
    });
  </script>
</body>
</html>
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers