ChainItem.js 680 B

1234567891011121314151617181920212223242526272829303132
  1. // 定义链的某一项
  2. function ChainItem(fn) {
  3. this.fn = fn;
  4. this.next = null;
  5. }
  6. ChainItem.prototype = {
  7. constructor: ChainItem,
  8. // 设置下一项
  9. setNext: function(next) {
  10. this.next = next;
  11. return next;
  12. },
  13. // 开始执行
  14. start: function() {
  15. return this.fn.apply(this, arguments);
  16. },
  17. // 转到链的下一项执行
  18. toNext: function() {
  19. if (this.next) {
  20. return this.start.apply(this.next, arguments);
  21. } else {
  22. return Promise.reject("无匹配的执行项目");
  23. // console.log('无匹配的执行项目');
  24. }
  25. }
  26. };
  27. export default ChainItem;