An implicit argument is a code smell: similar functions differ by a value embedded in their names instead of receiving it explicitly. Making that value first-class can clarify intent and reduce duplication. section 10.1 section 10.3
Use the express implicit argument refactoring in four steps:
- Identify the value encoded in the function name. section 11.1
- Add an explicit parameter for that value. section 11.1
- Replace the hard-coded value in the function body with the parameter. section 12.1
- Update calling code, then add runtime checks when only certain fields are valid. section 10.7
From named fields to one function
Instead of maintaining incrementQuantityByName(cart, name) and incrementSizeByName(cart, name), use incrementFieldByName(cart, name, field). The function reads item[field], increments the value, and writes it back. A check can reject every field except size and quantity. section 10.7 section 14.2
function setPriceByName(cart, name, price) {
var item = cart[name];
var newItem = objectSet(item, 'price', price); #1
var newCart = objectSet(cart, name, newItem);
return newCart;
}
function setQuantityByName(cart, name, quant) {
var item = cart[name];‡
var newItem = objectSet(item, 'quantity', quant); #1
var newCart = objectSet(cart, name, newItem);
return newCart;
}
function setShippingByName(cart, name, ship) { #2
var item = cart[name];
var newItem = objectSet(item, 'shipping', ship); #1
var newCart = objectSet(cart, name, newItem);
return newCart;
}
function setTaxByName(cart, name, tax) { #2
var item = cart[name];
var newItem = objectSet(item, 'tax', tax); #1
var newCart = objectSet(cart, name, newItem);
return newCart;
}
function objectSet(object, key, value) { #3
var copy = Object.assign({}, object);
copy[key] = value;
return copy;
}
Compare nearly identical cart-update functions whose field names are hard-coded, then generalize the field as an argument. section 10.3
The same smell can appear at deeper levels: making nested keys and modification behavior explicit leads toward reusable update functions and callbacks. section 14.10 section 14.11

