如何定义Ext.elevateFunction

问题描述 投票:0回答:1

“我在 ExtJS 文档中找不到定义的 Ext.elevateFunction,但它正在代码库中使用。我很想知道它是如何定义的。”

以下是代码库中Ext.elevateFunction函数的用法:

/** * 这是用户提供的目标

Ext.elevateFunction
。它包裹着 * 调用函数并通过调用 {@link Ext#fireIdle} 结束。 * @since 6.5.1 * @私人的 */

    doElevate: function() {
        var fn = elevateFn,
            args = elevateArgs,
            scope = elevateScope;

        // We really should never re-enter here, but we'll latch these vars just
        // in case.
        elevateFn = elevateArgs = elevateScope = null;
        elevateRet = args ? fn.apply(scope, args) : fn.call(scope);

        // Be sure to fire the idle event while elevated or its handlers will
        // be running in an unprivileged context.
        Ext.fireIdle();
    },

    /**
     * Runs the given `fn` directly or using the user-provided `Ext.elevateFunction`
     * (if present). After calling the `fn` the global `idle` event is fired using
     * the {@link Ext#fireIdle} method.
     *
     * @param {Function} fn 
     * @param {Object} [scope] 
     * @param {Array} [args] 
     * @param {Object} [timer] 
     * @return {Mixed} 
     * @since 6.5.1
     * @private
     */
    elevate: function(fn, scope, args
                      //<debug>
                      , timer // eslint-disable-line comma-style
                      //</debug>
    ) {
        var ret;

        if (args && !args.length) {
            args = null;
        }

        Ext._suppressIdle = false;

        //<debug>
        if (timer) {
            timer.tick();
        }
        //</debug>

        if (Ext.elevateFunction) {
            elevateFn = fn;
            elevateScope = scope;
            elevateArgs = args;

            // We reuse the same fn here to avoid GC pressure.
            Ext.elevateFunction(Ext.doElevate);

            ret = elevateRet;

            elevateRet = null;
        }
        else {
            ret = args ? fn.apply(scope, args) : fn.call(scope);

            Ext.fireIdle();
        }

        //<debug>
        if (timer) {
            timer.tock();
        }
        //</debug>

        return ret;
    },

我检查了 EXT 命名空间,elevateFunction 未定义。

extjs extjs4 extjs4.1 extjs4.2
1个回答
0
投票

Ext.elevateFunction函数可以自行设置,主要用于委托事件。

Ext.elevateFunction = function(callbackFn, scope, args) {
    // do your stuff
    Ext.callback(callbackFn, scope, args);
}

Ext中使用的主要结构是:

if (Ext.elevateFunction) {
    Ext.elevateFunction(this.elseFn, this, args);
} else {
    this.elseFn(args);
}
© www.soinside.com 2019 - 2024. All rights reserved.