> For the complete documentation index, see [llms.txt](https://packhouse-doc.metalsheep.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://packhouse-doc.metalsheep.com/the-instance/plugin.md).

# Plugin

Packhouse的Plugin只能存在於實體化的對象，沒有全局註冊的行為。

> [Order](/plugins/order.md)是我們提供的套件> ，也是一個簡單的開發範例。

{% hint style="info" %}
我們可以藉由我們不推薦你直接使用`plugin`，請參閱正規化方法[Main](/the-instance/main.md)。
{% endhint %}

```javascript
const Order = require('packhouse/plugins/Order')
const Packhouse = require('packhouse')
const packhouse = new Packhouse()

packhouse.plugin(Order)

console.log(packhouse.order()) // Order
```

## Develop

Plugin是一個`class`，會在`constructor`的第一個參數中接收到實體化的Packhouse對象。

```javascript
class MyPlugin {
    constructor(packhouse) {
        packhouse.hello = function() {
            console.log(`hello world.`)
        }
    }
}

const Packhouse = require('packhouse')
const packhouse = new Packhouse()

packhouse.plugin(MyPlugin)
packhouse.hello() // hello world.
```

## Repeat Registration Of Plugins

當Packhouse偵測到相同的Class對象，則不會有任何反應。

```javascript
packhouse.plugin(Order)
// 以下行為不會觸發任何事
packhouse.plugin(Order)
```

這意味著當你基於外部開發時引入某些Plugin時能有更多元的註冊行為：

```javascript
const group = {
    install(group, options, packhouse) {
        packhouse.plugin(require('packhouse/plugins/Order'))
    }
}
```
