Function argument hints

# Gareth Heyes (7 years ago)

I propose a new syntax for defining function argument hints. If you have a lot of arguments in a function it can be difficult to remember which argument is which. Using a hint allows you to easily see the argument required and can prevent you from passing an incorrect argument.

It would work like this:

function x(domNode, obj, someFlag) {
}

//here are the argument hints
x(domNode:dom, obj: o, someFlag: true)

So here the js engine looks up the argument hint and compares it to the function definition. If the hint does not match the function argument in the definition then a exception is thrown.

x(obj: o, someFlag: true) //error "obj" hint does not match "domNode" hint.

The hint easily allow you to see what argument you are using without having to look at the function definition and also prevent you passing an incorrect argument.

# T.J. Crowder (7 years ago)

I think you're talking about named parameters, or close enough anyway. Most recent discussion of named parameters (originally just "is there discussion of them?" but it went from there): esdiscuss.org/topic/named-paramters

Others probably as well if you search back further in the archives and meeting notes.

Note also overlap with parameter destructuring. It's a totally different thing, but can be used for some of the same use cases (long argument lists in particular).

-- T.J. Crowder

On Wed, Jul 26, 2017 at 2:09 PM, Gareth Heyes <gareth.heyes at portswigger.net>

wrote:

Hi all

# Gareth Heyes (7 years ago)

Ah yeah true there is some overlap there thanks.