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()
时传入参数:
javascript
jQuery.map([1, 2, 3], function(v, i, arg) { return v * 2 + arg; }, 'arg');