Skip to content

Commit

Permalink
Update getters-setters.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Dec 19, 2022
1 parent 79d76ea commit b50148e
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions docs/tutorials/getters-setters.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ below.
[require:getters/setters.*setters.*update skip]
```

## Passing Parameters using `$locals`

You can't pass parameters to your getter and setter functions like you do to normal function calls.
To configure or pass additional properties to your getters and setters, you can use the document's `$locals` property.

The `$locals` property is the preferred place to store any program-defined data on your document without conflicting with schema-defined properties.
In your getter and setter functions, `this` is the document being accessed, so you set properties on `$locals` and then access those properties in your getters examples.
For example, the following shows how you can use `$locals` to configure the language for a custom getter that returns a string in different languages.

```javascript
[require:getters/setters.*localization.*locale]
```

Differences vs ES6 Getters/Setters
----------------------------------

Expand All @@ -81,11 +94,3 @@ corresponding getter for `email`.
```javascript
[require:getters/setters.*setters.*vs ES6]
```

## $locals

You can use `$locals` to support internationalization for your application.

```javascript
[require:getters/setters.*localization.*locale]
```

0 comments on commit b50148e

Please sign in to comment.