# base/object (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/base/object/

Base object.

## Object

Base object.

Example: Inherit, clone and compare

```js
import { Object } from "./build/vanilla.js";

class Inventory extends Object {
	constructor() {
		super();
		this.itemNameList = [];
	}
}

const inventory = new Inventory();
inventory.itemNameList.push("sword");
const shallowCopy = inventory.clone();
const deepCopy = inventory.structuredClone();
inventory.itemNameList.push("shield");
console.log(shallowCopy.itemNameList.length, deepCopy.itemNameList.length);
console.log(inventory.equals(inventory), inventory.equals(deepCopy), Object.isValidate(null));
console.log(inventory.getInstanceId() === inventory.getInstanceId());
```

- `constructor()` (constructor, since 0.0.8): Constructor.
- `destroy()` (method, since 0.0.9): Destroys. (Invalidates the member variables of the current object)
- `equals(other)` (method, since 0.0.8): Equality comparison.
  - `other` any: Value to compare.
  - returns boolean: True if it is the same reference as this object. (false for null)
- `getInstanceId()` (method, since 0.0.8): Returns the instance's unique identifier.
  - returns string: Unique identifier in GUID form. (created on the first call, the same string is returned afterwards)
- `clone()` (method, since 0.0.8): Shallow clone of an instance.
  - returns this: A new object made by the same constructor with no arguments. (own enumerable fields and properties with both a getter and a setter are copied shallowly)
- `structuredClone()` (method, since 0.0.8): Deep clone of an instance.
  - returns this: A new object made by the same constructor with no arguments. (arrays and plain objects are rebuilt, class objects are copied by reference)
- `static isValidate(target)` (static, since 0.2.1): Returns whether the object is valid.
  - `target` any: Value to check.
  - returns boolean: True if it is neither undefined nor null.
