test.js 386 B

123456789101112131415161718192021222324
  1. var makeAFailure = (function() {
  2. function onSuccess(data) {}
  3. function onFailure(data) {
  4. throw new Error('failed!');
  5. }
  6. function invoke(data) {
  7. var cb = null;
  8. if (data.failed) {
  9. cb = onFailure;
  10. } else {
  11. cb = onSuccess;
  12. }
  13. cb(data);
  14. }
  15. function test() {
  16. var data = {failed: true, value: 42};
  17. invoke(data);
  18. }
  19. return test;
  20. })();