# callable objects with properties

{% tabs %}
{% tab title="📗 參考" %}
* 📘 [Call Signatures](https://www.typescriptlang.org/docs/handbook/2/functions.html#call-signatures)
* 📗 [Callable Objects and callAsFunction() in Swift](https://www.vadimbulavin.com/call-as-function-in-swift/)
* 📗 [What’s new in Swift 5.2](https://www.hackingwithswift.com/articles/212/whats-new-in-swift-5-2)
{% endtab %}

{% tab title="Second Tab" %}

{% endtab %}
{% endtabs %}

```typescript
type DescribableFunction = {

  // other properties
  description: string;
  
  (someArg: number): boolean;  // ⭐️ 注意：參數與回傳值之間不是用 => ❗️
//╰─── ⭐️ call signature ───╯
};

function doSomething(fn: DescribableFunction) {
  console.log(fn.description + " returned " + fn(6));
}
```

比較 **`callAsFunction`** in Swift：

```swift
struct Dice {

    var lowerBound: Int
    var upperBound: Int

    // ⭐️ callAsFunction
    func callAsFunction() -> Int {
        (lowerBound...upperBound).randomElement()!
    }
}

let d6 = Dice(lowerBound: 1, upperBound: 6)
let roll1 = d6()
print(roll1)
```
