我不确定这个或参数在curry函数中适用于什么,因为参数绑定到宿主函数,在这种情况下是"a“,我不相信它实际上在任何地方都会被使用。
var _isPlaceholder = require('./_isPlaceholder');
/**
* Optimized internal one-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry1(fn) {
return function f1(a) {
if (arguments.length === 0 || _isPlaceholder(a)) {
return f1;
} else {
return fn.apply(this, arguments);
}
};
};
var _curry1 = require('./internal/_curry1');
/**
* Creates a new object from a list key-value pairs. If a key appears in
* multiple pairs, the rightmost pair is included in the object.
*
* @func
* @memberOf R
* @since v0.3.0
* @category List
* @sig [[k,v]] -> {k: v}
* @param {Array} pairs An array of two-element arrays that will be the keys and values of the output object.
* @return {Object} The object made by pairing up `keys` and `values`.
* @see R.toPairs, R.pair
* @example
*
* R.fromPairs([['a', 1], ['b', 2], ['c', 3]]); //=> {a: 1, b: 2, c: 3}
*/
module.exports = _curry1(function fromPairs(pairs) {
var result = {};
var idx = 0;
while (idx < pairs.length) {
result[pairs[idx][0]] = pairs[idx][1];
idx += 1;
}
return result;
});发布于 2017-04-17 06:51:47
这里使用arguments只是允许将多个参数应用于函数,同时确保至少提供一个非placeholder参数。
this的绑定只是确保使用计算curried函数时所用的相同this来调用底层函数。
https://stackoverflow.com/questions/43442171
复制相似问题