我试图理解为什么 __
在这段代码中工作正常:
function editAddress (id, addressId, model) {
return BusinessService
.getById(id)
.then(unless(
() => checkUrlValue(addressId, model.id),
rejectWithError(InvalidData.error('Invalid address data: Address id is different from request'))
))
.then(pipe(
updateModel(__, 'addresses', model, 'id', addressId),
juxt([ always(id), identity ]),
apply(BusinessService.editById)
))
.then(pipe(
prop('addresses'),
find(propEq('id', addressId))
))
}
function updateModel (entity, property, model, attr, id) {
return evolve({
[property]: pipe(
juxt([
findIndex(propEq(attr, id)),
pipe(
find(propEq(attr, id)),
mergeLeft(model)
),
identity
]),
apply(update)
)
})(entity)
}
既然调用的函数 ( updateModel ) 没有柯里化(Currying),为什么 __
在这种情况下仍然有效?
最佳答案
updateModel
未进行柯里化(Currying)处理,但它返回一个名为 evolve
的柯里化(Currying)函数的结果。第一个调用传入:
{
[property]: pipe(
juxt([
findIndex(propEq(attr, id)),
pipe(
find(propEq(attr, id)),
mergeLeft(model)
),
identity
]),
apply(update)
)
}
然后使用 entity
调用进化调用的结果,在您的情况下将是 __。如果不了解 evolve
的内部结构,就不可能进一步理解代码。
关于javascript - __ 应该只适用于柯里化(Currying)函数吗?为什么它在这里工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57891579/