如何访问此功能参数和ES6模块

时间:2018-09-26 13:52:07

标签: javascript jquery ecmascript-6

如何访问ES6模块/类中的this关键字?例如,在下面的示例中,$(this)指向WaypointController,而在使用旧样式代码的情况下,它会引用选定的元素。
我尝试使用参数,但无济于事。

export default class WaypointContoller {
    constructor() {
        this.WAYPOINT_CLASS = 'main .webzone-wrapper:not(.no-csstransitions) > div';
        this.ANIMATION_CLASS = isIE9() ? 'fadeInUpNoAnimation' : 'fadeInUp';
        this.OFFSET = '90%';
        this.doAnimations(this.WAYPOINT_CLASS, this.ANIMATION_CLASS);
    }

    doAnimations(waypointClass, animationClass) {
        let delayTime;
        const waypoint = new Waypoint({ // eslint-disable-line no-undef
            element: document.querySelector(waypointClass),
            handler: () => {
                delayTime += 100;
                $(this).delay(delayTime).queue((next) => {
                    $(this).toggleClass('animated');
                    $(this).toggleClass(animationClass);
                    delayTime = 0;
                    next();
                });
            },
            offset: this.OFFSET,
            triggerOnce: true,
        });
        console.log(waypoint);
    }

    static init() {
        $(document).ready(() => {
            new WaypointContoller(); // eslint-disable-line no-new
        });
    }
}

0 个答案:

没有答案