-1

我不明白为什么这个函数认为 a)从最后丢失了。当我放置)它时,它会创建一个自执行函数并生成不是我想要的 javascript。

作品

this.Events.off = (): any {
    var events = arguments[0],
        callback = arguments[1];
    if (typeof events === 'string' && typeof callback === 'function') {
        this._events.off.call(this._events, events, callback);
    }
    else if (typeof callback === 'function') {
        this._events.off.call(this._events, callback);
    }
};

错误

declare var $, Backbone;

export class WebControls {

    _events;
    Events;

    constructor (options? ) {

        this._events = $.extend({}, Backbone.Events);

        this.Events = {};

        this.Events.on = (events: string, cb: (event: any) => any) {
            this._events.on.apply(this._events, arguments);
        };

        this.Events.trigger = (eventName: string, ...args: any[]): any {
            this._events.trigger.apply(this._events, arguments);
        };

        this.Events.off = (events?: string, callback?: any) : any {
            if (typeof events === 'string' && typeof callback === 'function') {
                this._events.off.call(this._events, events, callback);
            } else if (typeof callback === 'function') {
                this._events.off.call(this._events, callback);
            }
        };
    }

}

红色波浪的屏幕截图 编译截图 编译截图 编译截图

我在这里盲目地遗漏了一些明显的东西吗?

4

1 回答 1

3

在屏幕截图代码中,您需要在参数列表后使用“函数”关键字或粗箭头。

于 2012-12-06T16:30:07.830 回答