Not exactly. You'd replace `foo` with the `argment()`ed version, and then
this:

    foo({ a: 'one', c: 'three' });

become equivalent to calling the original like this:

    foo('one', undefined, 'three');

It's just a wrapper to make writing functions which take options easier. So
instead of writing this:

    function foo(options){
    if ( ! options) {
    options = {};
    }
    if (options.a) {
    // ...
    }
    }

you write this:

    var foo = argment(function(a, b, c){
    if (a) {
    // ...
    }
    }, ['a', 'b', 'c']);

Maybe this is "tricky", but I want to play with it some more. I'm going to
throw in support for leading with normal arguments as soon as I get a chance
("Leave the first two arguments alone, combine the rest into an options
object."). I think it would work great for a case like the one in Jason's
link<http://blog.rebeccamurphey.com/objects-as-arguments-in-javascript-where-do-y>
.

On Mon, Jun 20, 2011 at 6:13 AM, xavierm02 <[email protected]> wrote:

> Wouldn't this do the exact same?
>
> function argument( f ) {
> return function ( ) {
> return f.apply( this, arguments );
>  };
> }
>
> And call is faster than apply
> http://jsperf.com/call-versus-apply
> so doing it for each function (for which you know the numer of used
> arguments) might be a bit better.
>
>  --
> 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]
>

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