3 ms·
We can tell how many arguments a function expects by accessing its length property. While that works for many cases it isn't generally true. For instance:
by couchand 11y ago
We can tell how many arguments a function expects by accessing its length property.
While that works for many cases it isn't generally true. For instance:
function wtf() { return arguments[0]; }
While that may seem like a ridiculous example, the following idiom is quite common in JS programming:
function accessor(value) {
if (typeof value === 'undefined') {
return getValue();
}
else {
setValue(value):
}
}
In general it's not a good idea to expect any particular value for a function's length property.
- kevincennis 11y agoRight, but you wouldn't curry those functions.