What I do is:
1. If I'm quite sure there will be only 1: foo(arg)
2. If I'm quite sure there will be only 2: foo(arg1, arg2)
2. If I'm quite sure there will be more than 2: foo(/*Object*/args)
3. if I'm not sure how many of them there will be in the future:
foo(/*Object*/args)
4. if I'm quite there will be a couple of them optionals:
foo(/*Object*/args)
5. if I'm not sure of anything: foo(/*Object*/args)
So to sum up: sure of 1 or 2 foo(arg1, arg2), or else
foo(/*Object*/args). Sometimes I always pass in Objects will arguments
just to make it flexible for the future. Sometimes I use "arguments"
object. I think everything is up to you, don't think it's really important.
Fran
On 13/01/11 16:37, Arlo wrote:
I am developing a JS API for my employer and I constantly ask myself
how I should accept params into my methods. So I figured I would ask
the professionals.
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 ) { ... }
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.
-------------
Arlo Carreon
@mexitek
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/jsmentors@jsmentors.com/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/jsmentors@googlegroups.com/
To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com