为什么jslint要求`getComputedStyle()`有一个窗口。字首?

时间:2014-07-15 17:03:26

标签: window jslint

同时它不需要setInterval()。我发现这是不一致的,因为两者都在全局窗口变量上找到。

以下是我通过linter运行的功能:

// peaking animation
Pub.peakOut = function (elem, offset, delay, callback) {
    var privates = {};

    // constants initialization
    privates.RADIX = 10;
    privates.GRAN_TIME = 15;
    privates.GRAN_DIST = 1;
    privates.UNITS = 'px';

    // privates initialization
    privates.el = elem;
    privates.start = parseInt(window.getComputedStyle(privates.el).getPropertyValue("top"),
            privates.RADIX);

    privates.status = 'down';
    privates.end = privates.start + offset;
    privates.current = privates.start;
    privates.id = null;

    (function next() {
        if ((privates.status === 'down') && (privates.current < privates.end)) {
            privates.current += privates.GRAN_DIST;
            privates.el.style.top = privates.current + privates.UNITS;
            if (!privates.id) {
                privates.id = setInterval(next, privates.GRAN_TIME);
            }
        } else if ((privates.status === 'down') && (privates.current === privates.end)) {
            privates.status = 'up';
            Priv.resetInterval(privates);
            setTimeout(next, delay);
        } else if ((privates.status === 'up') && (privates.current > privates.start)) {
            privates.current -= privates.GRAN_DIST;
            privates.el.style.top = privates.current + privates.UNITS;
            if (!privates.id) {
                privates.id = setInterval(next, privates.GRAN_TIME);
            }
        } else if ((privates.status === 'up') && (privates.current === privates.start)) {
            Priv.resetInterval(privates);
            callback();
        }
    }());
};

0 个答案:

没有答案