# 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'))
    }
}
```


---

# 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://packhouse-doc.metalsheep.com/the-instance/plugin.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.
