javascript - jquery map方法的 arg 参数仅限于内部使用?
大家讲道理
大家讲道理 2017-04-10 15:36:14
0
1
696

jquery 1.7.1中的map()的第三个参数arg为什么要注释仅限于内部使用?

javascript// arg is for internal usage only
map: function(elems, callback, arg) {
    var value, key, ret = [],
        i = 0,
        length = elems.length,
        // jquery objects are treated as arrays
        isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ((length > 0 && elems[0] && elems[length - 1]) || length === 0 || jQuery.isArray(elems));

    // Go through the array, translating each of the items to their
    if (isArray) {
        for (; i < length; i++) {
            value = callback(elems[i], i, arg);

            if (value != null) {
                ret[ret.length] = value;
            }
        }

        // Go through every key on the object,
    } else {
        for (key in elems) {
            value = callback(elems[key], key, arg);

            if (value != null) {
                ret[ret.length] = value;
            }
        }
    }

    // Flatten any nested arrays
    return ret.concat.apply([], ret);
}

还有像each()makeArray都有声明。那么“仅限内部使用”到底是什么意思?明明我可以在调用map()时传入参数:

javascriptjQuery.map([1, 2, 3], function(v, i, arg) {
    return v * 2 + arg;
}, 'arg');
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
黄舟

猜想可能是测试需要。

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template