In Javascript, should appending to the signature of a callback be considered a breaking change?
I.e. given an operation op(target, callback)
should changing it from callback(item, index, array)
to callback(item, index, array, root)
result in a new major release according to semver?
The spec specifies:
increment the MAJOR version when you make incompatible API changes
and the two signatures are not incompatible, as the new one encompasses the old, seeming to suggest a new major version is not required.
On the other hand, consider this (admittedly slightly contrived) example:
function doTheThing(item, index, array, doItDifferently) {
if (doItDifferently)
// Do something unusual and amazing with the arguments
else
// Do the same old boring thing with the arguments
}
// Use doTheThing as a callback to the operation:
op(target, doTheThing)
// doTheThing is also used directly:
doTheThing(arr[0],0,arr,true)
doTheThing
is a valid callback, but might be used elsewhere in the code in its more elaborate form. This would break if the callback signature were changed.
BadIdeaException is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.