I really don't think that there is a big memory overhead with one approach or 
another (correct me if I am wrong). I personally prefer using formal parameters 
for functions with one or two parameters total and objects for functions with 
more complicated set of arguments. Especially when you are dealing with 
optional arguments. There is nothing uglier than having to write something 
like: myfunc(1, 2, 3, null, null, "a", "b"); just to skip a couple of optional 
parameters that you don't need to at the moment. As an example, take the 
jQuery.ajax function and try to rewrite it using the formal parameters approach.

Anton


On Thursday, June 16, 2011 at 3:09 PM, Matthew Bramer wrote:

> Please excuse my lack of correct terminology (feel free to correct it!), but 
> I have an ongoing debate where I work about this. I see some people build up 
> their functions like this:
> 
> function ManyParams(param1, param2, param3, param4, param5, param6) {
> //stuff
> }
> 
> I say *not* to do that and just have one object as your parameter:
> 
> function OneParam(options) {
> //stuff
> }
> 
> My question to you guys is, which approach uses memory the most efficient? 
> I've been told that using an object would lengthen the script and will add 
> weight to it. (I don't really agree here)
> I see a lot of libraries using the approach that I describe, using an object 
> as a parameter. It seems that it's the easiest to maintain as well. 
> 
> I'd love to know if there is a fiddle out there that could prove the 
> pros/cons of both. On that note, how could I measure the difference in memory 
> usage?
> 
> Thanks for your time,
> Matt
> 
>  -- 
>  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] 
> (mailto:[email protected])

-- 
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]

Reply via email to