That's certainly doable. right now it just accept strings but it could
certainly be changed to also accept a hash.
let's say for a url request function, i can make it support something like
this:
have(arguments,
{ opt:
{ method: 'optional string'
, url: 'string'
, body: 'optional object' }
, callback: 'function'
});
I think that should covers most of the use cases short of implementing
jsonschema (which would be overkill).
But usually I have smaller methods though, will see if this is not too hard
to implement. : )
On Monday, March 18, 2013 5:45:18 PM UTC+7, Eric Muyser wrote:
>
> I've done a lot of programming and this is definitely useful. I've come up
> with a few times but never follow through with using it. The jQuery core
> has a lot of argument type checking and should probably use something like
> this so it's cleaner and clear which arguments it accepts, but that's why
> it has docs. If you don't have docs, this is more useful. If you only
> accept 1 argument, usually options, eg. options = {myParam: 4, isThis: 10}
> so you can use it as such: myFunction({myParam: 10, isThis: function()
> {}}); then that's the case where I always want to use something like this.
> I don't like how argument lists can get long and polluted, eg.
> myFunctionDoesAwesome('with this', 'and this argument', null, null, 10, 20,
> 303, null, null, true); and so I would use 1 param options with default
> values, and in that case I want validation against each possible argument.
>
> On Mon, Mar 18, 2013 at 7:31 PM, chakrit <[email protected]<javascript:>
> > wrote:
>
>> The use case is just to simplify arguments validation, which for me, is
>> getting repetitive and cumbersome in a project I'm currently building.
>>
>> So I wrote the module.
>>
>> Added an example.js here:
>> https://github.com/chakrit/have/blob/master/example.js if it'll helps.
>>
>> On Sunday, March 17, 2013 1:35:38 PM UTC+7, Pavel Kostenko wrote:
>>>
>>> Didn't get it, can you provide a real life use case with explanation?
>>
>> --
>> --
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines:
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to [email protected]<javascript:>
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "nodejs" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.