1234567891011121314151617181920212223242526272829303132 |
- // 定义链的某一项
- function ChainItem(fn) {
- this.fn = fn;
- this.next = null;
- }
- ChainItem.prototype = {
- constructor: ChainItem,
-
- // 设置下一项
- setNext: function(next) {
- this.next = next;
- return next;
- },
-
- // 开始执行
- start: function() {
- return this.fn.apply(this, arguments);
- },
-
- // 转到链的下一项执行
- toNext: function() {
- if (this.next) {
- return this.start.apply(this.next, arguments);
- } else {
- return Promise.reject("无匹配的执行项目");
- // console.log('无匹配的执行项目');
- }
- }
- };
- export default ChainItem;
|