# Limit Property Setters

setter/getterより明示的なset/get関数(例えば`setBar`や`getBar`関数)を使うことをお勧めします。

次のコードを考えてみましょう：

```typescript
foo.bar = {
    a: 123,
    b: 456
};
```

setter/getterの存在する例:

```typescript
class Foo {
    a: number;
    b: number;
    set bar(value:{a:number,b:number}) {
        this.a = value.a;
        this.b = value.b;
    }
}
let foo = new Foo();
```

これはプロパティのsetterの良い使い方ではありません。最初のコードサンプルを読んでいる人は、fooの何かが変わるとは思っていません。一方、`foo.setBar(value)`を呼び出す人は、`foo`で何かが変わるかもしれないと考える可能性が高いです。

> ボーナスポイント：異なる複数の関数がある場合は、参照を探す方が良いです。TypeScriptツールでは、getterまたはsetterの参照が見つかった場合は両方を取得しますが、明示的な関数呼び出しでは関係がある関数への参照のみを取得します。


---

# Agent Instructions: 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:

```
GET https://typescript-jp.gitbook.io/deep-dive/main-1/propertysetters.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
