> For the complete documentation index, see [llms.txt](https://guide-angular.wishtack.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide-angular.wishtack.io/ecmascript-6+/named-parameters.md).

# Named Parameters

Les paramètres ordonnées nuisent à la lisibilité du code et au refactoring.

```javascript
class Customer {
    constructor(firstName, lastName, email, phoneNumber) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
        this.phoneNumber = phoneNumber;
    }
}

new Customer('Foo', null, null, '123');
```

Malheureusement, les named parameters n'existent pas mais une solution de contournement native est possible grâce au destructuring.

## Named Parameters avec un seul paramètre.

```javascript
class Customer {
    constructor(args) {
        this.firstName = args.firstName;
        this.lastName = args.lastName;
        this.email = args.email;
        this.phoneNumber = args.phoneNumber;
    }
}

new Customer({
    firstName: 'Foo',
    phoneNumber: '123'
});
```

... mais cette approche n'est pas très IDE-friendly. L'utilisateur de la classe ne verra pas clairement les paramètres attendus.

## Destructuring

```javascript
class Customer {
    constructor(args = {}) {
    
        const {firstName, lastName, email, phoneNumber = null} = args;
    
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
        this.phoneNumber = phoneNumber;
    }
}
```

Hop ! On gagne l'initialisation des valeurs par défaut.

Ou encore mieux :

```javascript
class Customer {
    constructor({firstName, lastName, email, phoneNumber = null} = {}) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
        this.phoneNumber = phoneNumber;
    }
}
```

## Recyclage

Pour des objets peu complexes, ce constructeur nous évite d'implémenter des "factories".

```javascript
const customer = new Customer({firstName: 'Foo'});

const customerFromJson = new Customer(JSON.parse(data));

const customerCopy = new Customer(customer);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://guide-angular.wishtack.io/ecmascript-6+/named-parameters.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
