Re:Combinator Recipes for Working With Objects in JavaScript
by wylee on Saturday December 15, 2012 @03:28PM
(#4926243)
The `maybe` in the article allows for this ambiguous situation:
In my mind, all of these calls to `maybe_fn` should do the same thing. Maybe not, though?
[ Parent
| on HN ]
Re:Combinator Recipes for Working With Objects in JavaScript
by jrajav on Saturday December 15, 2012 @03:38PM
(#4926275)
This is a good point, and may be an argument for having a "formal_maybe" or perhaps having it check at least as many arguments as there are formal arguments. However, I don't think that this situation would be as important in practical use. You would normally use this function to allow for passed arguments to be null or undefined - not to allow for some arguments not to be passed.
Re:Combinator Recipes for Working With Objects in JavaScript
by ufo on Sunday December 16, 2012 @08:58AM
(#4928310)
function.length is certainy a PITA dus to the `arguments` issue that was mentioned. In particular, function.length doesn't work on functions returned by our own combinators, a big no-no!
In the end I adopted a convention where every function that depends on the number of arguments of something else receives that number sa a first parameter:
maybe(2, function(a,b){ ... })