On Thu, Jan 13, 2011 at 9:37 AM, Arlo <[email protected]> wrote:
> Here is my scenario:
> 1.) I know a handful of basic methods that I need to implement right
> now.
> 2.) I do not know if functionality in these methods will expand in the
> future
>
> Example Method:
> A.) function drawPolygon( points, polyOptions ) { ... }
> B.) function drawPolygon( options ) { ... }
>
Giving too many options to developers can be quite costly in the long-run in
terms of testing and other boilerplate burdens. I prefer the args Object
approach because then you can make a consistent API for all your methods, as
well as an easy checker function that will validate all your input against
expected types. If you give the developers a consistent API and you don't
alter it from method to method, I don't think anyone will complain that you
don't expose all arguments.
> I feel that with option B I can expand functionality a lot easier than
> with option A. Does anyone have advice or common pitfalls when taking
> approach B? I appreciate any input.
>
You're right. Again, while jQuery does this various ways, I think that
passing an object literal into a function is much cleaner API than many
arguments in the function signature.
-Anatoly
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]