4 ms·
Seen lots of these at this point. I still don't really understand their purpose. Its not hard, and doesn't require much, if any, more code than the config opti
by jdc0589 13y ago
Seen lots of these at this point. I still don't really understand their purpose.
Its not hard, and doesn't require much, if any, more code than the config options for libraries like this to just handle your arguments normally.
required arguments get defined in your function signature. You assign optional args to local variables defined within your function body via the arguments object. It's pretty easy.
- adam-a 13y agoThe original motivation was providing a single way to deal with a combination of default arguments, optional arguments and the sort of homebrew polymorphism that a lot of libraries use, where a function takes 4 different types of thing and runs through a bunch type tests before doing anything. For functions with longer parameter lists this should hopefully be more readable too. It's clear what types can be passed to a function. Out of interest, what other libraries like this have you seen? I did a quick check myself and couldn't find anything comparable.
- ufo 13y agoAnother good reason to assign everything to a local variable ASAP is that if I leave everything in the args object then jshint can't help me prevent typos when accessing fields from that object.