jQuery的递归值到另一个函数

时间:2018-09-17 20:07:56

标签: javascript jquery jquery-deferred

我想将myFunc函数的true或false值返回给beforeClose函数。如果延迟解决,那么我想返回true,如果延迟拒绝,那么我想从myFunc返回false到beforeClose函数。

但是我无法直接从myFunc返回true或false到beforeClose函数。有什么建议吗?

beforeClose: function () {
                var val = self.myFunc();
                return val;
            },

myFunc: function () {
            var self = this;

            var callback = function () {
                return true; // I want to return true from here to beforeClose function.
            };

            var callback2 = function () {
                return false;// I want to return false from here to beforeClose function.
            };

                var deferred = $.Deferred();
                deferred.done(callback);
                deferred.fail(callback2);
                self.events.myEvent(deferred); // I will resolve or reject the deffered object from this myEvent.

        }

0 个答案:

没有答案