Yeah, I'll admit that is sort of a hack. But it does works very reliably from my experience. There will be problem if you have numeric keys but that is not the case with arguments since you can't name arguments with numbers anyway.
See here for more info: http://stackoverflow.com/questions/280713/elements-order-in-a-for-in-loop Quoting from an answer there: "All browsers respect definition order with the exception of Chrome and Opera which do for every non-numerical property name." Although, I'll definitely consider using an array input if there is a way to do it nicely syntax-wise. Thanks for pointing out anyway : ) Appreciated. On Tuesday, March 19, 2013 12:22:11 PM UTC+7, Adam Ahmed wrote: > > Be careful with this. If I'm reading your code correctly, you are relying > on the order of that object literal matching the order of the arguments > object. This is not guaranteed, as far as I know. This would cause your > arguments to be matched against the wrong schemas. > > I'd suggest replacing the object input with an array input where order is > guaranteed. > > On Sunday, 17 March 2013 05:23:29 UTC+11, chakrit wrote: >> >> If you are like me and you write a lot of precondition checks in your >> functions to validate the arguments, >> then I think you will like this module, here's a sample of what it can do: >> >> var have = require('have'); >> >> function safeFunc(id, options, callback) { >> have(arguments, >> { id : 'string or number' >> , options : 'optional object' >> , callback : 'function' >> }); >> } >> >> Basically a very short and concise DSL for validating arguments. >> >> Install with `npm install have --save` >> >> Head over to https://github.com/chakrit/have to check the README if you >> are interested. : ) >> >> >> - chakrit >> http://chakrit.net >> > -- -- 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.
