# \_instanceOf

### 说明

&#x20;模拟实现原生的`instanceOf`

### 源码

<https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/others/_instanceOf>

### 用法

{% code title="\_instanceOf.test.ts" %}

```typescript
import { _instanceOf } from "../../utility/others/_instanceOf";

describe('_instanceOf tests...', () => {

  test('_instanceOf should return the correct result', () => {
    interface PersonConstructor {
      new(): PersonInterface;
    };
    interface PersonInterface {
    };

    class Person implements PersonInterface {
      constructor() {
      }
    }

    const received: Array<{
      left: any,
      right: any,
    }> = [
        {
          left: new Person(),
          right: Person,
        },
        {
          left: {},
          right: Object,
        },
        {
          left: [],
          right: Array,
        },
        {
          left: [],
          right: Object,
        },
        {
          left: 2,
          right: 8,
        },
        {
          left: 'ddzy',
          right: {},
        },
        {
          left: {},
          right: null,
        },
      ];
    const expected = [true, true, true, true, false, false, false,];

    received.forEach((v, i) => {
      const result = _instanceOf(v.left, v.right);

      expect(result).toBe(expected[i]);
    });
  });

});
```

{% endcode %}


---

# 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://ddzy.gitbook.io/ts-utility-plugins-docs/utility/utility-others/_instanceof.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.
