>
> We've discussed this extensively before and there doesn't seem to be many
> plausible use cases for the function length property.
Here's the only use case that I've encountered (admittedly not particularly
strong): Overriding the behavior of a function/method based on the
"signature" of an input function:
function withCallback(callback) {
// Do something which generates an error...
var error = new Error("abc");
// Use callback.length to override behavior...
if (callback.length >= 2)
callback(null, error);
else
throw error;
}
// Throws error
withCallback(val => { ... });
// Logs error
withCallback((val, err) => { if (err) console.log(err); });
// Throws, even though it has the err parameter
withCallback((val = 123, err) => { ... });
Not great, but...
Another thought I had was that someone might want to use defaults to
replace undefined actual parameters with null values:
function f(a = null, b = null) { ... }
f(void 0); // normalized to null
f.length = 0; // Intentional?
Again, not great, but...
Kevin
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss