# .extend()

### extend(extensions)

| **Parameter** | **Description**                                                                                                                                      |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| extensions    | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></p><p>An object with the methods</p> |

| **Returns**                                               | **Description**                                                    |
| --------------------------------------------------------- | ------------------------------------------------------------------ |
| [Database](https://simpldb.js.org/documentation/database) | A modified version of the base Database class with the new methods |

####

{% hint style="warning" %}
You can define methods using [normal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions) and/or [arrow](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) functions, but in order to access the base class methods with the "this" keyword, you must use a normal function.
{% endhint %}

```javascript
const extendedDb = db.extend({
  // Add new methods
  chunk(key, count) {
    const array = this.get(key);

    const newArr = [];

    for (var i = 0; i < array.length; i+=count)
      newArr[i/count] = array.slice(i, i+count);
      
    return newArr;
  },

  // Overwrite existing methods
  delete: (key) => {
    // Whatever you wanna do here.
  }
})

extendedDb.set('someArray', [1,2,3,4,5]); // [1,2,3,4,5]

extendedDb.chunk('someArray', 2); // [[1,2], [3,4], [5]]
```
