As a javascript dev, there is one useful use case where breaking the DRY principle has a benefit - the arguments object built-into the function body.
arguments is an Array-like object, but it is not an Array. To use array methods on it, one usually borrows from the Array prototype to convert it to an array:
var _slice = Array.prototype.slice
function () {
var args = _slice.call(arguments)
// "args" is an array of the arguments this function has received
}
This causes two performance caveats:
_slice.call creates a new bound function every time it executes.arguments -arguments overloading, arguments mutation and leaking arguments. If you pass arguments to a function, that counts as leaking arguments.Since you can't pass arguments around as function parameters (if you want your code to be optimized), you're forced to do this in every function:
function () {
var args = []
for (var i = 0; i < arguments.length; i++) {
args[i] = arguments[i]
}
}
This is solved in ES2015, where one can use rest parameters:
function (...args) {
}
But an interesting reason to break the DRY principle nonetheless :)